Description
One way to do this might be as follows:
a) Create a frame with a TableLayoutPanel. Choose a number of rows and columns that works well with whatever size you decide to make the frame.
b) Populate the panel with Labels or Buttons.
c) Maybe set a border for each label label.BorderStyle so you can clearly see each label.
d) Add a label.MouseClick to each label and in the mouseClicked method change the labels background color to the next color in your chosen palette of colors,
e) There are several ways you could determine what the next color should be, but one simple way might be to get label.BackColor on the label to see its current color and decide what the next color should be based on that.
Another interesting way to do this particular exercise is to create a subclass of Label that does all the label setup in its constructor. You can then add specialty fields and methods to your Label
Some helpful things to setup the TableLayoutPanel
1. Set ColumnCount and RowCount
2. Call on the TableLayoutPanel RowStyles.Clear() and ColumnStyles.Clear()
3. Add to the TableLayoutPanel RowStyles.Add(new RowStyle(SizeType.Percent, 1)) and
ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1)) for each row and column (in a loop of course)
Some helpful things to setup labels in the TableLayoutPanel
1. Dock.Fill
2. Anchor the label to all 4 sides
Colors can be used like this: label.BackColor = Color.White; or you can make your own colors using the static method in Color: Color.FromArgb().
Reviews
There are no reviews yet.