[英]How to create label-like explanatory text fields in C#?
I have a C# form. 我有一个C#表格。 I want to write some explanations. 我想写一些解释。 I tried RichTextBox and multi-line TextBox. 我尝试了RichTextBox和多行TextBox。 I make them read-only, changed cursor to default in order to get the indicated part in the image below but I cannot prevent selection. 我将它们设置为只读,将光标更改为默认值,以便获得下图中的指示部分,但我不能阻止选择。 The format I want is like Label: you cannot select text, cursor is not IBeam etc. However label is very limited, I am not able to get multi-line. 我想要的格式就像标签:您不能选择文本,光标不是IBeam等。但是标签非常有限,我无法获得多行。 How can I create such explanation part in winforms as shown with a red arrow below? 如何在winforms中创建这样的解释部分,如下面的红色箭头所示?
example image http://desmond.imageshack.us/Himg191/scaled.php?server=191&filename=csharpbox.jpg&res=medium 示例图片http://desmond.imageshack.us/Himg191/scaled.php?server=191&filename=csharpbox.jpg&res=medium
You can use a Label
, just change AutoSize
to false. 您可以使用Label
,只需将AutoSize
更改为false即可。
Label l = new Label();
l.AutoSize = false;
l.Text = "Hello\nWorld";
您可以得到与该标签相似的Label,只需禁用AutoSize,文本将按预期换行。
It's not a good idea to insert a lot of text in a label. 在标签中插入很多文本不是一个好主意。 You could replace the label with a textbox and play with its display properties to make it look like a label. 您可以将标签替换为文本框,并使用其显示属性来使其看起来像标签。 For example, remove the border, make the background color transparent. 例如,删除边框,使背景色透明。
If you still want to use a label maybe you should check this solution 如果您仍然想使用标签,也许应该检查此解决方案
如何在说明中使用工具提示?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.