[英]Add NewLine to label's Text at design time
How can I add newlines to a Label
's Text
at design time? 在设计时如何在Label
的Text
中添加换行符? There are some posts on Stack Overflow on how to do this in code-behind, but there is no post about that for design time yet, it seems? 在堆栈溢出中有一些关于如何在代码隐藏中执行此操作的文章,但是似乎还没有关于设计时的文章。
When you click on the label Text property in the Property window for the label, a drop down will appear in which you can, when you press Enter , go to the new line. 在标签的“属性”窗口中单击标签“文本”属性时,将显示一个下拉列表,您可以在其中按Enter键转到新行。 I just tried it, and it works in Visual Studio 2010. 我刚刚尝试过,它可以在Visual Studio 2010中使用。
Here's a screenshot to clarify: 这是要说明的屏幕截图:
Design Time \\r\\n will do the trick - 设计时间\\ r \\ n可以解决问题-
label1.Text = "Multi-line \r\nlabel"
Also you can try setting in designer generated code - 您也可以尝试在设计器生成的代码中进行设置-
this.label2.Location = new System.Drawing.Point(151, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Multi-line \r\n label";
Run time - 运行 -
label1.Text = "Multi-line" + Environment.NewLine + "label";
您可以在字符串中使用<br />
,例如:
MyLabel.Text = "This is my text" + "<br />" + "This is my new line text";
When you get the formatting box to drop down, use 'Shift+Enter' to go to a new line. 当下拉格式框时,使用“ Shift + Enter”转到新行。 'Enter' just causes the box to close. “输入”仅使框关闭。 At least, that's my experience in VS2015. 至少,这就是我在VS2015中的经验。
Set Autosize to False using Properties > Layout > Autosize then set Width and Height parameters depending on your text size using Properties > Layout > Size. 使用“属性”>“布局”>“自动大小”将“自动大小”设置为False,然后使用“属性”>“布局”>“大小”根据文本大小设置“宽度”和“高度”参数。 This worked for me with Width as 60 and Height as 40 for Label to display like below. 这对我来说有效,宽度为60,高度为40,标签显示如下。
3: Auto 3:自动
H: Home H:首页
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.