J
Jim
I have created a windows form that contains several tab
pages which contain a panels. On a tab page I am trying
to dynamically create a series of buttons in that pages
panel. I am failing because I can not find the proper way
to point to the specific tab page and its panel when
creating the buttons.
I also need to dynamically change the background color
property of each button as it is clicked.
I can dynamically create the buttons in a blank form with
the code below, but am unable to create them in the tab
page-panel and I can not dynamically change the
background color within my click event.
Any help would be greatly appreciated.
Code is below (I used the sample on the net for the
structure):
This is fired from a click event in a statically placed
button.
For sX = 0 To 5
Dim bX As New Button
bX.Name = "Level" + m_controlCount.ToString
bX.Text = "C" + m_controlCount.ToString
bX.Width = 60
bX.Height = 20
bX.Location = New Point(m_Location.X + 70,
m_Location.Y)
m_Location.X += 65
AddHandler bX.Click, AddressOf
LevelHandler_Click
AddHandler bX.MouseHover, AddressOf
LevelHandler_MouseHover
Controls.Add(bX)
m_controlCount += 1
bX.Visible = True
Next sX
Here is the LevelHandler code that does not work. The
entire form changes color:
Private Sub LevelHandler_Click(ByVal sender As
System.Object, ByVal e As EventArgs)
If TypeOf sender Is Button Then
If System.Drawing.ColorTranslator.ToOle
(Button.DefaultBackColor) =
System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Red) Then
BackColor =
System.Drawing.ColorTranslator.FromOle(&H8000000F)
Else
BackColor = System.Drawing.Color.Red
End If
End If
End Sub
pages which contain a panels. On a tab page I am trying
to dynamically create a series of buttons in that pages
panel. I am failing because I can not find the proper way
to point to the specific tab page and its panel when
creating the buttons.
I also need to dynamically change the background color
property of each button as it is clicked.
I can dynamically create the buttons in a blank form with
the code below, but am unable to create them in the tab
page-panel and I can not dynamically change the
background color within my click event.
Any help would be greatly appreciated.
Code is below (I used the sample on the net for the
structure):
This is fired from a click event in a statically placed
button.
For sX = 0 To 5
Dim bX As New Button
bX.Name = "Level" + m_controlCount.ToString
bX.Text = "C" + m_controlCount.ToString
bX.Width = 60
bX.Height = 20
bX.Location = New Point(m_Location.X + 70,
m_Location.Y)
m_Location.X += 65
AddHandler bX.Click, AddressOf
LevelHandler_Click
AddHandler bX.MouseHover, AddressOf
LevelHandler_MouseHover
Controls.Add(bX)
m_controlCount += 1
bX.Visible = True
Next sX
Here is the LevelHandler code that does not work. The
entire form changes color:
Private Sub LevelHandler_Click(ByVal sender As
System.Object, ByVal e As EventArgs)
If TypeOf sender Is Button Then
If System.Drawing.ColorTranslator.ToOle
(Button.DefaultBackColor) =
System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Red) Then
BackColor =
System.Drawing.ColorTranslator.FromOle(&H8000000F)
Else
BackColor = System.Drawing.Color.Red
End If
End If
End Sub