-
Feb 5th, 2014, 05:45 AM
#1
Thread Starter
New Member
Want to add a Click Event Please Help.
Hello i am making a boxed painting application and i have the grid but i want to add a click command so when you click the picturebox the background changes colour.
Code:
Public Class Form1
'Left to Right
'Dim Row As Integer = 0
'Up Down
'Dim Column As Integer = 0
Dim Box(10, 10) As PictureBox
''' <remarks>
''' (11, 0) (11, 1) (11, 2) (11, 3) (11, 4) (11, 5) (11, 6) (11, 7) (11, 8) (11, 9)
''' (10, 0) (10, 1) (10, 2) (10, 3) (10, 4) (10, 5) (10, 6) (10, 7) (10, 8) (10, 9)
''' (9, 0) (9, 1) (9, 2) (9, 3) (9, 4) (9, 5) (9, 6) (9, 7) (9, 8) (9, 9)
''' (8, 0) (8, 1) (8, 2) (8, 3) (8, 4) (8, 5) (8, 6) (8, 7) (8, 8) (8, 9)
''' (7, 0) (7, 1) (7, 2) (7, 3) (7, 4) (7, 5) (7, 6) (7, 7) (7, 8) (7, 9)
''' (6, 0) (6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6) (6, 7) (6, 8) (6, 9)
''' (5, 0) (5, 1) (5, 2) (5, 3) (5, 4) (5, 5) (5, 6) (5, 7) (5, 8) (5, 9)
''' (4, 0) (4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (4, 7) (4, 8) (4, 9)
''' (3, 0) (3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8) (3, 9)
''' (2, 0) (2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8) (2, 9)
''' (1, 0) (1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8) (1, 9)
''' (0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) (0, 6) (0, 7) (0, 8) (0, 9)
''' </remarks>
#Region "Runtime Load"
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
BuildMap()
End Sub
#End Region
#Region "Build Grid"
Public Sub BuildMap()
For row = 0 To 10
For column = 0 To 10
DrawBox(row, column)
Next
Next
End Sub
#End Region
#Region "Draw"
Public Sub DrawBox(row As Integer, column As Integer)
Box(row, column) = New PictureBox
Box(row, column).size = New Point(50, 50)
Box(row, column).BorderStyle = BorderStyle.FixedSingle
Box(row, column).BackColor = Color.BurlyWood
Box(row, column).Location = New Point((Box(row, column).Width * column), (Box(row, column).Height * row))
Debug.Print("Column:" & column.ToString)
Debug.Print("Row:" & row.ToString)
Me.Controls.Add(Box(row, column))
End Sub
#End Region
#Region "Clicked"
Private Sub pic_Click(sender As Object, e As EventArgs)
Dim thisPic As PictureBox = DirectCast(sender, PictureBox)
thisPic.BackColor = Color.Aqua
End Sub
#End Region
End Class
-
Feb 5th, 2014, 05:57 AM
#2
Thread Starter
New Member
Re: Want to add a Click Event Please Help.
EDIT: Adding Picture:
-
Feb 5th, 2014, 07:00 AM
#3
Re: Want to add a Click Event Please Help.
When you create a PictureBox, use the AddHandler statement to register your method as a handler for its Click event. Just make sure that you use RemoveHandler to remove the event handler when you are done with the PictureBox, which you should also be disposing when you're done with it.
-
Feb 5th, 2014, 07:01 AM
#4
Re: Want to add a Click Event Please Help.
Just add the click handler for each pictureBox.
Something like, after setting the properties for the picturebox.
vb.net Code:
AddHandler DirectCast(Box(row, column), PictureBox).Click, AddressOf pic_Click
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Feb 5th, 2014, 07:19 AM
#5
Thread Starter
New Member
Re: Want to add a Click Event Please Help.
Thank You So Much For Your Help! Its just what i wanted it to do! Thanks Heaps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|