Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public int CalculateHeight(Label lbl)
{
    Graphics g = lbl.CreateGraphics();
    return Convert.ToInt32(g.MeasureString(lbl.Text, lbl.Font).Width);
}

private void button1_Click(object sender, EventArgs e)
{
    label1.Text = "The Computer location is now called This PC, and you can still use the Documents, Music, Pictures, and Videos folders to save your files. You just browse to these folders differently in File Explorer. To browse the locations on your PC, including the folders that used to appear under Libraries, expand This PC in the left pane. ";
    //label1.Text = "The Computer location is now called This PC, and you can still use the Documents, Music, Pictures, and Videos folders to save your files.";
    label1.Height = CalculateHeight(label1) / 14;
    MessageBox.Show(label1.Height.ToString());
}



in this code I cant decide the label's new height.
Please Help me..
Thanks in Advance.
Posted

1 solution

 
Share this answer
 
Comments
Sid_Joshi 19-Aug-14 9:02am    
I already applied AutoSize=false; with above code and I just wants to adjust label height instead of width.
ZurdoDev 19-Aug-14 9:21am    
From the solution:

"One basic strategy is to set the MaximumSize.Width property so the label cannot grow horizontally beyond the window edge or overlap another control. It will now automatically wrap long text, adding lines vertically."
Thanks7872 19-Aug-14 9:27am    
I am afraid of the next gen developers..Seriously..They need each...each and everything ready made..
Sid_Joshi 19-Aug-14 9:28am    
please try to understand my problem by running above code.
If u cant solve my problem then ignore my problem don't try to show your attitude.
Thanks7872 19-Aug-14 9:31am    
Why? Have you seen the above comment? Did you understand what it states? Have you tried doing that? If No,why? If yes, what is the issue now?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900