Add NewLine to label's Text at design time

隐身守侯 提交于 2019-12-21 06:46:55

问题


How can I add newlines to a Label's Text at design time? 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?


回答1:


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. I just tried it, and it works in Visual Studio 2010.

Here's a screenshot to clarify:




回答2:


Design Time \r\n will do the trick -

      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";



回答3:


You can use <br /> in your string, for example :

MyLabel.Text = "This is my text" + "<br />" + "This is my new line text";



回答4:


When you get the formatting box to drop down, use 'Shift+Enter' to go to a new line. 'Enter' just causes the box to close. At least, that's my experience in VS2015.




回答5:


Set Autosize to False using Properties > Layout > Autosize then set Width and Height parameters depending on your text size using Properties > Layout > Size. This worked for me with Width as 60 and Height as 40 for Label to display like below.
3: Auto

H: Home



来源:https://stackoverflow.com/questions/13295116/add-newline-to-labels-text-at-design-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!