vb.net events

IWeb

Member
Joined
Sep 12, 2003
Messages
11
Hello,

I started to use VB.net yesterday and I came to a maybe silly question:
"How do I add events to form objects like a picturebox?". When I double click on a form object I can only edit the click-event of the object. but there are also events like "doubleclick" or "onmousedown" - how do I edit (add code to) them?

Thank you,
 
two possibilities:

#1:
go to the Form Load Event handler (created when you doubleclick on the form in the Designer..) and add the following lines:

[VB]Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
.... some code...

add the EventHandler to the PictureBox:
AddHandler myPictureBox.MouseDown, Addressof myPictureBox_MouseDown

.... some other code...
End Sub[/VB]

of course now you have to write the eventHandler you just hooked to the MouseDown-Event of the PictureBox:

[VB]Private Sub myPictureBox_MouseDown(ByVal sender as Object, ByVal e as MouseEventArgs)
some code here...
MessageBox.Show("MouseDown on PictureBox!")
End Sub[/VB]

this was the first way to handle Events...

#2:

go to the Codeview of your form. on top of the Code you see two comboboxes. go to the first (the left) one and select for example "myPictureBox" (or however you named your PictureBox). Then go to the second one and select for example "MouseDown" and voila youve got your Eventhandler - easy isnt it?! ;)

yea... thats about it. I hope you understood everything and thisll help you!

Andreas
 
Back
Top