vb.net - onClick Event For Picturebox -
I have more than 30 picture boxes, as a window to the name
PictureBox1 PictureBox2 PictureBox3. I have to write the same procedure for each one of them for the click function. I want to be able to write only one handler which will be used for all pictureboxes. To handle the click event and call the same function.
For some technical examples. Sorry for the JavaScript format
picturebox.onclick () {var a = get_index (this); // Some of the clickboxed pictureboxes (A); }
If you are using the keyword handles
, For example, can add multiple event names to the handles
section:
Private sub-OnClick (sender in the form of object), events such as ARGs) handles picturebox 1.Click, PictureBox2. Click, PictureBox3 Click 'Click' Handles for Picture Box 1, Picturebox 2 and Picturebox 3 and subs. Alternatively, you can declare event handler method without the Handles
section, and then the manual Attach it yourself to events automatically, such as: Private Sub OnClick (as the sender of the object, and in the form of EventArgs). 'End Sub' ... AddHandler PictureBox1 .Click, AddressOf OnClick AddHandler PictureBox2.Click, AddressOf OnClick AddHandler PictureBox3.Click, AddressOf OnClick Or, if you have a list of picture box controls, you can add event to ndlers in a loop, like this:
My picture box ( ) As PictureBox = {PictureBox1, PictureBox2, PictureBox3} for each of my picture box Addictor Boxes AddHandler i.Click, AddressOf OnClick Next
Or, From the control
name can be accessed from the collection:
I control the form of integer = 1 to 30 dim C = Mi Control ("Picturebox" & amp; I.ToString ()) AddHandler c.Click, AddressOf OnClick Next
Keep in mind, however, if you manually AddHandler
call, you need to call RemoveHandler
Split the event handler later
It looks weird, on the surface, there are so many picture boxes, though though. You can consider custom-highlighting your content in a single control or dynamically load control over run-time.
Comments
Post a Comment