I am painting a 2-dimensional array of labels on the form. The user can input the size of the array from 1x1 to 8x8. I am alternating the color of the rows or columns between red and blue. After the labels are painted on the form, i want to toggle the color of rows or columns. Now, if the program, alternates the color of the rows, after pushing the toggle button then the next time the toggle button is pushed i would like the columns to alternate in color. I am able to get the rows or columns to aternate in color; however,, i can not get the program to alternate between rows and columns. I used a Boolean; however, not effectively. Any help would be appreciated.
CODE
Public Class finalPartBForm
Private gridLabelArray(,) As Label
'Private rowInteger, columnInteger As Integer
Private rowsInteger, columnsInteger As Integer
Dim toggleBoolean As Boolean = True
Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
Try
rowsInteger = Integer.Parse(rowTextBox.Text) - 1
columnsInteger = Integer.Parse(columnTextBox.Text) - 1
If rowsInteger < 0 Or rowsInteger > 7 Then
MessageBox.Show("Please enter an integer between 1 & 8", "Data entry error", MessageBoxButtons.OK)
rowTextBox.Text = ""
rowTextBox.Focus()
ElseIf columnsInteger < 0 Or columnsInteger > 7 Then
MessageBox.Show("Please enter an integer between 1 & 8", "Data entry error", MessageBoxButtons.OK)
columnTextBox.Text = ""
columnTextBox.Focus()
Else
ReDim gridLabelArray(rowsInteger, columnsInteger)
Dim rowIndex, columnIndex As Integer
For rowIndex = 0 To rowsInteger
For columnIndex = 0 To columnsInteger
Dim theLabel As New Label
With theLabel
'.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
If toggleBoolean Then
If columnIndex Mod 2 = 0 Then
.BackColor = Color.Red
Else
.BackColor = Color.Blue
End If
.SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
Controls.Add(theLabel)
gridLabelArray(rowIndex, columnIndex) = theLabel
End If
End With
Next
Next
If toggleBoolean = False Then
ReDim gridLabelArray(rowsInteger, columnsInteger)
'Dim rowIndex, columnIndex As Integer
For rowIndex = 0 To rowsInteger
For columnIndex = 0 To columnsInteger
Dim theLabel As New Label
With theLabel
'.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
If rowIndex Mod 2 = 0 Then
.BackColor = Color.Red
Else
.BackColor = Color.Blue
End If
.SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
Controls.Add(theLabel)
gridLabelArray(rowIndex, columnIndex) = theLabel
End With
Next
Next
End If
End If
Catch ex As Exception
MessageBox.Show("Input must be an integer between 1 & 8", _
"Data entry error", MessageBoxButtons.OK)
End Try
Me.Width = 35 * columnsInteger + 225
Me.Height = 40 * rowsInteger + 225
End Sub
Private Sub toggleButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toggleButton.Click
Dim rowIndex, columnIndex As Integer
For rowIndex = 0 To rowsInteger
For columnIndex = 0 To columnsInteger
If toggleBoolean = True Then
If gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red Then
gridLabelArray(rowIndex, columnIndex).BackColor = Color.Blue
Else
gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red
End If
ElseIf toggleBoolean = False Then
If gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red Then
gridLabelArray(rowIndex, columnIndex).BackColor = Color.Blue
Else
gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red
End If
End If
Next
Next
toggleBoolean = True
'If toggleBoolean = False Then
' ReDim gridLabelArray(rowsInteger, columnsInteger)
' 'Dim rowIndex, columnIndex As Integer
' For rowIndex = 0 To rowsInteger
' For columnIndex = 0 To columnsInteger
' Dim theLabel As New Label
' With theLabel
' '.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
' If rowIndex Mod 2 = 1 Then
' .BackColor = Color.Red
' Else
' .BackColor = Color.Blue
' End If
' .SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
' Controls.Add(theLabel)
' gridLabelArray(rowIndex, columnIndex) = theLabel
' End With
' Next
' Next
'End If
End Sub
End Class