Hi there, i have developed this code (with a bit of help) that will generate a grid of pictureboxes (function as buttons) which reserve individual seats. This is my code:
Public Class Form1
Dim i As Integer
Dim j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Me.i = 0 To My.Settings.Rows
For Me.j = 0 To My.Settings.Collums
Dim Seatpicture As New PictureBox
Seatpicture.Location = New Point(10 + (j * 45), 15 + (i * 80))
Seatpicture.ImageLocation = (My.Settings.DriveLetter & ":\Clear.gif")
Seatpicture.SizeMode = PictureBoxSizeMode.StretchImage
Seatpicture.Size = New Size(40, 78)
Seatpicture.Load()
Me.Controls.Add(Seatpicture)
AddHandler Seatpicture.MouseEnter, AddressOf Mouse_Enter
AddHandler Seatpicture.MouseLeave, AddressOf Mouse_Leave
AddHandler Seatpicture.MouseClick, AddressOf Mouse_Click
Next
Next
End Sub
Private Sub Mouse_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
If DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Clear.gif") Then
DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Blue.gif")
End If
End Sub
Private Sub Mouse_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
If DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Blue.gif") Then
DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Clear.gif")
End If
End Sub
Private Sub Mouse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Blue.gif") Then
DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Green.gif")
ActualTotal.Text = ActualTotal.Text + 5
Else
DirectCast(sender, PictureBox).ImageLocation = (My.Settings.DriveLetter & ":\Blue.gif")
ActualTotal.Text = ActualTotal.Text - 5
End If
End Sub
Image of form 1:
http://postimg.org/image/winqc1w3j/
(Green is selected, blue is highlighted)
My problem is that i want to make the program remember which seats were selected, but i have no way to identify each individual picturebox (with the exception of the sender function, which can't be used here) I want to put my pictureboxes in a 2D array which remembers the Row and collumn of the picturebox, but i am unsure how to do this.
Can anyone help?
Thanks.