Hi all,
Hopefully someone can help me out with this one.
I have a form which gets populated by 15 buttons dynamically at runtime (these need to be dynamic as there will be a user config file at some point)
What I need these buttons to do is to open a specific form when clicked. Which form that opens will be dealt with in the config file.
Public Class frm_MainScreen
Private Sub frm_MainScreen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim count As Integer
Dim ImageDir As String
Dim xpos As Integer
Dim ypos As Integer
xpos = 12
ypos = 12
ImageDir = (My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\TrinityMediaCenter\Images\")
Me.BackgroundImage = Image.FromFile(ImageDir & "bg_main.png")
For count = 1 To 15
Dim btnMain(count) As System.Windows.Forms.Button
btnMain(count) = New System.Windows.Forms.Button
'*************Need to use the form name as the button name*************
btnMain(count).Name = "**********"
btnMain(count).Width = 190
btnMain(count).Height = 190
btnMain(count).BackgroundImage = Image.FromFile(ImageDir & "buttons\main_back.png")
btnMain(count).Image = Image.FromFile(ImageDir & "buttons\main_front.png")
btnMain(count).BackColor = Color.Transparent
btnMain(count).ForeColor = Color.White
btnMain(count).Text = "Button " & count
btnMain(count).FlatAppearance.BorderSize = 0
btnMain(count).FlatStyle = FlatStyle.Flat
btnMain(count).FlatAppearance.MouseDownBackColor = Color.Transparent
btnMain(count).FlatAppearance.MouseOverBackColor = Color.Transparent
btnMain(count).Location = New Point(xpos, ypos)
Me.Controls.Add(btnMain(count))
xpos = xpos + 202
If xpos > 822 Then
xpos = 12
ypos = ypos + 202
End If
AddHandler btnMain(count).Click, AddressOf btnMain_Click
Next
End Sub
Private Sub btnMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim buttonPressed As System.Windows.Forms.Button = sender
'********************************************************
'*************Not sure what needs to be here*************
'*************I need to open the form based *************
'*************on which button is pressed *************
'********************************************************
End Sub
End Class
Hope someone can help.
Thanks
TheMightySpud