c# - 标签尺寸不正确

标签 c# winforms

我正在尝试制作一个 Label在 C# 中,它将以固定宽度和可变高度的方式换行文本。我正在使用这段代码:

Label newMsg = new Label();
newMsg.AutoSize = true;
newMsg.MaximumSize = new Size(350, 400); //setting fixed width, max height to avoid being too high for container
newMsg.MinimumSize = new Size(350, 0); //fixed width, height doesn't matter
newMsg.Text = msg;
newMsg.Location = new Point(4, 7);
newMsg.BackColor = Color.Red; //red to see the actual size in contrast to its container

但它不起作用。我尝试做一些研究,无论文本是一个单词还是一整段,newMsg.Height始终是 23。 有谁知道为什么?谢谢

最佳答案

就像其他人已经说过的那样,将 AutoSize 属性更改为 false,

newMsg.AutoSize = false;

关于c# - 标签尺寸不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24304524/

相关文章:

c# - VS 2017 版本 15.5.1 - Unresolved System.Net.Http 项目引用

c# - 保持 UI 线程空闲

c# - MVC5 Razor html.dropdownlistfor 当值在数组中时设置选择

c# - USING block 在网站和 Windows 窗体中的行为不同

c# - 在 winform 上找到隐藏的控件并使它们在运行时可见?

c# - 由于 NativeWindow,如何修复 Excel VSTO 项目中的 ThreadAbortException?

.net - Windows 窗体中的选项卡索引

c# - 在 F# 中启用 Web 请求通过反向代理

c# - 如何优化这个 FormatAccountNumber 方法?

c# - 在不增加字体大小的情况下增加文本框高度