I'm using C#. Sometimes the text returned from a web service (which I display in a label) is too long and gets cut off on the edge of the form. Is there an easy way to add a newline to the label if it's not going to fit on the form?
Thanks
Text = sText; lblDescription. Location = new Point(iX1, iY + 5);
Step 2: Drag the Label control from the ToolBox and drop it on the windows form. You are allowed to place a Label control anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the Label control to set the Size property of the Label.
Windows. Forms namespace. Add a Label control to the form - Click Label in the Toolbox and drag it over the forms Designer and drop it in the desired location. If you want to change the display text of the Label, you have to set a new text to the Text property of Label.
We can also use a Panel control to create a multiline label in C#. We can place the desired label inside a panel and then handle the ClientSizeChanged event for the panel. The ClientSizeChanged event is invoked whenever the size of a control inside the panel changes. We can resize the label with the Label.
If you set the label to autosize
, it will automatically grow with whatever text you put in it.
In order to make it word wrap at a particular width, you can set the MaximumSize property.
myLabel.MaximumSize = new Size(100, 0);
myLabel.AutoSize = true;
Tested and works.
If you always want to be able to see the data, you can set the Label's container's AutoScroll
property to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With