vb.net events

IWeb

Newcomer
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:

Visual Basic:
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

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

Visual Basic:
Private Sub myPictureBox_MouseDown(ByVal sender as Object, ByVal e as MouseEventArgs)
   'some code here...
   MessageBox.Show("MouseDown on PictureBox!")
End Sub

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 you've got your Eventhandler - easy isn't it?! ;)

yea... that's about it. I hope you understood everything and this'll help you!

Andreas
 
Back
Top