简体   繁体   English

如何在C#中创建类似标签的说明性文本字段?

[英]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.

相关问题 如何在类似标签的控件中显示简短的只读FlowDocument - How to display short read only FlowDocument in a label-like control 如果标签宽度不适合C#Windows窗体应用程序中的文本宽度,如何使标签中的文本像(选取框)一样移动? - How can i make the text in the label move like in (marquee) if the label width not fit the text width in C# windows form application? 如何像编辑器中一样在C#标签中显示文本 - How can I display a text in a C# label like written in the editor C#:如何在Visual Studio 2012中将诸如标签或文本框值之类的文本从窗体发送到Crystal报表? - C#: How to send text like label or textbox value from form to crystal reports in visual studio 2012? 如何在C#表单中修改标签文本 - How to modify label text in C# forms C#如何使标签文本不可见 - C# how to make label text invisible C# 如何在列表视图中设置标签文本? - C# How to set label text in a listview? C#如何在画布上创建标签 - C# How to create a label onClick on a canvas 如何在c#驱动程序中为mongo集合中的所有文本字段创建全文搜索? - How do you create a full text search for all text fields in a mongo collection in the c# driver? 使用Label控件在c#winform中创建循环字幕文本 - using Label control to create looping marquee text in c# winform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM