Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-05-2009
Member
 
Join Date: Apr 2009
Posts: 78
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.
Reply With Quote
  #2  
Old 23-05-2009
Member
 
Join Date: Jan 2009
Posts: 140
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
Reply With Quote
  #3  
Old 23-05-2009
Member
 
Join Date: Jan 2009
Posts: 143
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
Reply With Quote
  #4  
Old 23-05-2009
Member
 
Join Date: Jan 2009
Posts: 99
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)         
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to set Autosize Label .NET Framework"
Thread Thread Starter Forum Replies Last Post
.NET Framework 3.5 Service Pack 1 and .NET Framework 3.5 Family Update (KB951847) x86 M.Scarlet Server Update Service 10 05-05-2011 11:13 AM
.net Compact Framework autosize textbox Avanindra Software Development 2 04-06-2009 07:24 PM
How do i get same compact label autosize in .net Dharmesh Arora Software Development 2 19-05-2009 02:02 PM
Microsoft .NET Framework 3.5 Service Pack 1 and .NET Framework 3.5 Family Update (KB951847) x64 Installation problem BP Windows Update 8 16-03-2009 08:29 AM
How to Disable Autosize of Images in Internet Explorer and Firefox Mastermind Tips & Tweaks 0 21-01-2009 08:13 PM


All times are GMT +5.5. The time now is 11:09 PM.