Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 9,089 times

Related Categories

Manipulate Multiple Windows Forms Controls

thing123

This code simply demonstrates how to ask the user for a colour, and then enumerate all the button controls within a panel setting their background colour.

'place a panel on your form called pnlObjects
'in that panel place some buttons
'add a button to you form and call it cmdChangeColour
Private Sub cmdChangeColour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChangeColour.Click Try Dim cDlg As New ColorDialog Dim selColour As Color = Color.White 'get the user colour
With cDlg .ShowDialog() .AnyColor = True selColour = .Color End With 'set all the controls in the panel to that colour
For Each c As Control In pnlObjects.Controls If TypeOf c Is Button Then Dim b As Button = CType(c, Button) With b .BackColor = selColour End With End If Next Catch ex As Exception Throw New Exception(ex.Message) End Try End Sub End Class

Comments