Handling events

  • Thread starter Thread starter Sean
  • Start date Start date
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
 
* "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?
 
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
 
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
 
Back
Top