Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i change label size in vb.net to new size (available in a textbox)

eg : if textbox contains number =50 i want the label width =50

What I have tried:

Label6.Size = New System.Drawing.Size(Val(TextBox1.Text), 90)
Posted
Updated 5-Nov-19 14:10pm
Comments
Ralf Meier 8-Apr-18 14:48pm    
Basicly Wendelius gave you an alternative Solution.
Independant from that should your code work too if Textbox1 contains a value which could be converted to a number by Val.
When do you assign the new Size-Value to the Label ? Which Event from which Control causes this ...?

Instead of modifying the Size property try to set the Width property of the label control. In other words:
VB
Label6.Width = Val(TextBox1.Text)

Also ensure that Label.AutoSize Property (System.Windows.Forms)[^] is not set
 
Share this answer
 
v2
Comments
Maciej Los 7-Apr-18 9:16am    
5ed!
Wendelius 10-Apr-18 0:13am    
Thanks!
Make sure to set AutoSize property of the label to False; Otherwise, you cannot set any custom size.

VB
label6.AutoSize = False
label6.Width = CInt(TextBox1.Text)
 
Share this answer
 
v2
Just change the minimum size of your label to whatever you desire.
 
Share this answer
 
This worked for me
labelSesion.Width = labelSesion.Text.Length * 6
 
Share this answer
 
Comments
Dave Kreskowiak 27-Oct-19 14:11pm    
There's a ton of problems with this, namely font size, varying character width, whitespace content of the string, ...

There is far batter ways of doing this without taking uneducated guesses at string length.

And it doesn't even answer the OP's question.

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