Results 1 to 4 of 4

Thread: How to set Autosize Label .NET Framework

  1. #1
    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.

  2. #2
    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

  3. #3
    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

  4. #4
    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)         
    }

Similar Threads

  1. Replies: 10
    Last Post: 05-05-2011, 11:13 AM
  2. .net Compact Framework autosize textbox
    By Avanindra in forum Software Development
    Replies: 2
    Last Post: 04-06-2009, 07:24 PM
  3. How do i get same compact label autosize in .net
    By Dharmesh Arora in forum Software Development
    Replies: 2
    Last Post: 19-05-2009, 02:02 PM
  4. Replies: 8
    Last Post: 16-03-2009, 08:29 AM
  5. Replies: 0
    Last Post: 21-01-2009, 08:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,246,703.62975 seconds with 17 queries