By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Handling an Event

P: n/a
I have an class that I want to have a PictureBox as a
member of (passed in), and I want to be able handle the on
click event for it. How do I do it?

Right now, the PictureBox is declared:

Public Class MyClass

Friend WithEvents f_PictureBox As
System.Windows.Forms.PictureBox

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

.....

End Sub

End Class

But it doesn't except the last f_PictureBox.Click as
valid. I get a Handle requires WithEvents variable error.

Help

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Nevermind, I must be tired, figured it out. Thanks.
-----Original Message-----
I have an class that I want to have a PictureBox as a
member of (passed in), and I want to be able handle the onclick event for it. How do I do it?

Right now, the PictureBox is declared:

Public Class MyClass

Friend WithEvents f_PictureBox As
System.Windows.Forms.PictureBox

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

.....

End Sub

End Class

But it doesn't except the last f_PictureBox.Click as
valid. I get a Handle requires WithEvents variable error.

Help

.

Nov 20 '05 #2

P: n/a
On Wed, 14 Jan 2004 06:08:54 -0800, Sean wrote:
I have an class that I want to have a PictureBox as a
member of (passed in), and I want to be able handle the on
click event for it. How do I do it?


Check out the AddHandler and RemoveHandler statements. When you pass in
the PictureBox, you can use AddHandler to assign the event handler to the
PictureBox.

HTH

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #3

P: n/a
After getting over being stupid this morning, I actually
did it more cleverly than that, and just have an object
reference in my class already associated with the correct
event handler, so all I have to do is assign that
reference by setting a MyClass.PictureBox =
pbSomePictureBox.

-----Original Message-----
On Wed, 14 Jan 2004 06:08:54 -0800, Sean wrote:
I have an class that I want to have a PictureBox as a
member of (passed in), and I want to be able handle the on click event for it. How do I do it?

Check out the AddHandler and RemoveHandler statements.

When you pass inthe PictureBox, you can use AddHandler to assign the event handler to thePictureBox.

HTH

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mailaddress.
.

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.