I have a form with a split panel. In the one split are a group of buttons which I want to programmatically change the color of the last pressed button. The following loop seems to run correctly and set the colors correctly but the form doesn't represent that. Once the loop is completed and I recheck the button colors, they revert to previous state.
For Each formControl As Control In Me.FormSplitContainer.Panel1.Controls
If formControl.GetType() Is GetType(Button) Then
If CType(sender, Button) Is CType(formControl, Button) Then
CType(sender, Button).BackColor = Color.White
Else
CType(sender, Button).BackColor = System.Drawing.SystemColors.ControlDark
End If
End If
Next
I can get the desired effect by doing the below code but seems less elegant and would obviously require updates as buttons would be added or removed.
DataFeedButton.BackColor = System.Drawing.SystemColors.ControlDark
IncentiveButton.BackColor = System.Drawing.SystemColors.ControlDark
CType(sender, Button).BackColor = Color.White
Anyone see what I am missing?