Font ForeColor Issues

  • Thread starter Thread starter Beebs
  • Start date Start date
B

Beebs

I've written a small routine that basically when the user presses on
one of the buttons on the screen its text changes to red and all the
rest of the buttons text should be set to black (except for a few,
including the button that was pressed). To get the name of the button
I'm using some code found on Chris Tacke's blog which works perfectly.

The problem I'm having, is it doesn't work! If I comment out the line
of code that sets the color to black in the For routine, then the
color will change to red of the pressed button, but obviously that
does me no good. Why would setting other button's text inhibit a
different section of code from executing?

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim btn As Button = CType(sender, Button)

btn.ForeColor = System.Drawing.Color.Red
G_ROOM = btn.Text

For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button Then
Dim room As String = ControlEx.GetControlName(ctrl)
If room <> "_btn" & G_ROOM And room <> "_btnBack" And
room <> "_btnNext" And room <> "_btnOther" Then
btn.ForeColor = System.Drawing.Color.Black
End If
End If
Next
End Sub
 
Ah, silly me, I was still calling the button I wanted changed to
red...I should have been doing this in my for loop:

ctrl.ForeColor = System.Drawing.Color.Black
 
Back
Top