954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Set size of a label from text boxes

Hey,
I tried to change the size of a label from 2 text boxes, but doesn't work. Here is my code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        y = TextBox2.Text
        x = TextBox3.Text
        Form2.Label1.Size = New Size(y, x)
    End Sub

textbox2 is width and textbox3 is height.
It doesn't change and I don't know why. Can someone help me with this?

petrelutza
Newbie Poster
10 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Turn "AutoSize" off on the Label1.

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 
Turn "AutoSize" off on the Label1.

I tried and still not working, any other ideas?

petrelutza
Newbie Poster
10 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Hey, I tried to change the size of a label from 2 text boxes, but doesn't work. Here is my code: VB.NET Syntax (Toggle Plain Text)

1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 2. y = TextBox2.Text 3. x = TextBox3.Text 4. Form2.Label1.Size = New Size(y, x) 5. End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click y = TextBox2.Text x = TextBox3.Text Form2.Label1.Size = New Size(y, x) End Sub textbox2 is width and textbox3 is height. It doesn't change and I don't know why. Can someone help me with this?

Forgot to add:

Dim y As Integer
    Dim x As Integer
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        y = TextBox2.Text
        x = TextBox3.Text
        Form2.Label1.Size = New Size(y, x)
    End Sub
petrelutza
Newbie Poster
10 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

You should do it like this:

In form1 you need a button to show your form2 like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fr As New Form2
        fr.Show()
    End Sub


In form2 you can do it like this:

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim y As Integer
        y = Form1.TextBox1.Text
        Dim x As Integer
        x = Form1.TextBox2.Text

        Label1.Size = New Size(y, x)
    End Sub
Luc001
Posting Whiz
376 posts since Mar 2010
Reputation Points: 85
Solved Threads: 98
 
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
        Dim W As Integer = TextBox1.Text
        Dim H As Integer = TextBox2.Text
        Label1.Size = New Point(W, H)
    End Sub

I use it and it work Turn off Autosize And to test it work just change BackColor
to other color
the font size didn't change as it label size you must code it

Dim fnt As Font
fnt = TextBox1.Font
Label1.Font = New Font(fnt.Name, 12, FontStyle.Bold)
trpsjt2008
Light Poster
42 posts since Apr 2010
Reputation Points: 10
Solved Threads: 2
 

VB.NET Syntax (Toggle Plain Text)

1. Private Sub Button1_Click(ByVal sender As System.Object, _ 2. ByVal e As System.EventArgs) Handles Button1.Click 3. Dim W As Integer = TextBox1.Text 4. Dim H As Integer = TextBox2.Text 5. Label1.Size = New Point(W, H) 6. End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim W As Integer = TextBox1.Text Dim H As Integer = TextBox2.Text Label1.Size = New Point(W, H) End Sub I use it and it work Turn off Autosize And to test it work just change BackColor to other color the font size didn't change as it label size you must code it VB.NET Syntax (Toggle Plain Text)

1. Dim fnt As Font 2. fnt = TextBox1.Font 3. Label1.Font = New Font(fnt.Name, 12, FontStyle.Bold)

Well, them how can I change the size of text using those text boxes?

petrelutza
Newbie Poster
10 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 
Private Sub Button1_Click(ByVal sender As System.Object, _
Dim TxtSz As Integer = Textbox1.text
Dim fnt As Font
fnt = Label1.Font
Label1.Font = New Font(fnt.Name, TxtSz, FontStyle.Regular)
End Sub

This Work For Me

trpsjt2008
Light Poster
42 posts since Apr 2010
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: