cortastic
Programmer
- Nov 4, 2008
- 3
This should be a simple question! I am attempting to use a series of comboboxes to change the forecolor of a series of labels during runtime.
So far, the only method I have found that works is the tedious method:
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.Text
Case "Green"
lbl1.ForeColor = Color.Green
Case "Blue"
lbl1.ForeColor = Color.Blue
Case "Black"
lbl1.ForeColor = Color.Black
Case "Red"
lbl1.ForeColor = Color.Red
End Select
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Select Case ComboBox2.Text
Case "Green"
lbl2.ForeColor = Color.Green
Case "Blue"
lbl2.ForeColor = Color.Blue
Case "Black"
lbl2.ForeColor = Color.Black
Case "Red"
lbl2.ForeColor = Color.Red
End Select
End Sub
I'd prefer to
a) not have to type all this code
b) have the program add items to the comboboxes for me or recognize the combobox values so I don't have to even worry about populating the comboboxes with a list.
I tried doing this:
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
lbl1.ForeColor = System.Drawing.Color.FromName(ComboBox1.SelectedText)
End Sub
It doesn't return any errors, thankfully, but it also doesn't change the label color.
I have taught myself visual basic, so I'm sure I'm just missing something basic. I'd be truly appreciative of any suggestions and the opportunity to learn something new!
So far, the only method I have found that works is the tedious method:
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.Text
Case "Green"
lbl1.ForeColor = Color.Green
Case "Blue"
lbl1.ForeColor = Color.Blue
Case "Black"
lbl1.ForeColor = Color.Black
Case "Red"
lbl1.ForeColor = Color.Red
End Select
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Select Case ComboBox2.Text
Case "Green"
lbl2.ForeColor = Color.Green
Case "Blue"
lbl2.ForeColor = Color.Blue
Case "Black"
lbl2.ForeColor = Color.Black
Case "Red"
lbl2.ForeColor = Color.Red
End Select
End Sub
I'd prefer to
a) not have to type all this code
b) have the program add items to the comboboxes for me or recognize the combobox values so I don't have to even worry about populating the comboboxes with a list.
I tried doing this:
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
lbl1.ForeColor = System.Drawing.Color.FromName(ComboBox1.SelectedText)
End Sub
It doesn't return any errors, thankfully, but it also doesn't change the label color.
I have taught myself visual basic, so I'm sure I'm just missing something basic. I'd be truly appreciative of any suggestions and the opportunity to learn something new!