locked
Change Font Size of Label During Runtime RRS feed

  • Question

  • Hi,
    I have a form with some labels. If the labels equal certain text, then I want the font size of the label to change.  For example, if the text reads "apple", I want the font size of the label to be 16.  If the text reads "banana", I want the font size of the label to be 8.  This has to occur during runtime without any clicking of the label.  I have an idea of the code I want to write in order for this to work, but I need to know where to put the code for the labels.  I cannot put this under Label_Click or Form_Load.  Where can I put this code so that it works for the labels during runtime?  Thank you in advance.  I have VB2008.
    Sunday, August 23, 2009 12:45 AM

Answers

  •     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Contains("apple") Then
                Label1.Font = New Font(Label1.Name, 16)
            End If
            If TextBox1.Text.Contains("banana") Then
                Label1.Font = New Font(Label1.Name, 8)
            End If
        End Sub

    trujade. ;o)
    i like: VB General   google   fast cars   username password
    • Marked as answer by vb5newbie Sunday, August 23, 2009 2:38 AM
    Sunday, August 23, 2009 1:13 AM

All replies

  •     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Contains("apple") Then
                Label1.Font = New Font(Label1.Name, 16)
            End If
            If TextBox1.Text.Contains("banana") Then
                Label1.Font = New Font(Label1.Name, 8)
            End If
        End Sub

    trujade. ;o)
    i like: VB General   google   fast cars   username password
    • Marked as answer by vb5newbie Sunday, August 23, 2009 2:38 AM
    Sunday, August 23, 2009 1:13 AM
  • Thank you so much Trujade!  That was exactly what I was looking for!
    Sunday, August 23, 2009 2:39 AM