473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Handling an Event

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
3 894
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
3
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
4
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
4
by: Mythran | last post by:
I once read an article somewhere describing why we should not override the OnXXX methods of classes when you want to extend the functionality of a class. It stated that you should handle the event...
1
by: stmfc | last post by:
hi, for an event handling mechanism, we need an event object. (the object where the event actually occur) and we need an event handler, and we need a registration of the event handler to the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.