How to set Autosize Label .NET Framework
I wanted to create an application in which i wanted to create an Label and for that i have decided to develop in using .NET framework, and i have also read that label control has a AutoSize property, which wraps the text if it doesn't fit into specified label width. How do I set the property values in the autosize label I would like to have same capability on Compact Framework.
Re: How to set Autosize Label .NET Framework
You may use the following code for your autosize label or something similar to it.
Code:
Graphics Z = this.create_Graphics();
SizeF set_Size = Z.MeasureString(str, label1.Font); //get the size of the text
label1.set_Size = new Size((int)size.Width, label1.Size.Height); //set the size of the label
Re: How to set Autosize Label .NET Framework
Gets or sets a value indicating whether the control is automatically resized to display its entire contents.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Code:
<BrowsableAttribute(True)> _
Public Overrides Property AutoSize As Boolean
Visual Basic (Usage)
Code:
Dim instance As Label
Dim value As Boolean
value = instance.AutoSize
instance.AutoSize = value
Re: How to set Autosize Label .NET Framework
while searching for how to set Autosize Label on the internet I found this. Try this in your application.
Code:
public void Resize(Label label1)
{
Graphics P = Graphics.FromHwnd(this.Handle);
SizeF set_Size = P.MeasureString(label1.Text, label1.Font);
//gets the size of the text which will be displayed
label1.set_Size = new set_Size((int)size.Width, label1.Size.Height);
//sets the length of the label (same height)
}