Handling events

S

Sean

I have an object that I want to have a PictureBox as a
member of, and I want to be able handle the on click event
for that member PictureBox. How do I do it?

Right now, the PictureBox is declared:

Friend WithEvents f_PictureBox As
System.Windows.Forms.PictureBox

Private Sub PictureBox_Clicked(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
f_PictureBox.Click

But it doesn't except the last f_PictureBox.Click as valid.

Help
 
H

Herfried K. Wagner [MVP]

* "Sean said:
I have an object that I want to have a PictureBox as a
member of, and I want to be able handle the on click event
for that member PictureBox. How do I do it?

Right now, the PictureBox is declared:

Friend WithEvents f_PictureBox As
System.Windows.Forms.PictureBox

Private Sub PictureBox_Clicked(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
f_PictureBox.Click

But it doesn't except the last f_PictureBox.Click as valid.

Works perfectly for me. Do you get a compiler error or a runtime error?
 
B

Blake Weaver

That sub declaration looks right to me assuming you actually have a
PictureBox on your form by that same name and that you're not just declaring
the variable alone.

Any more info you can provide?

Blake
 
S

Sean

Well, it is not form, it is a class, and I am passing the
PictureBox in as part of the constructor. I want whatever
PictureBox I assign to the object to be handled by the
event. Thanks.

Public Sub New(ByVal PB as PictureBox)

f_PictureBox = PB

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top