Invoking a PictureBox click ?

C

Cerebrus99

Hi all,

The Click event handler of a button control can be invoked using the
Button.PerformClick method. But I have a Picturebox, whose click event
handler I want to invoke. RaiseEvent doesn't seem to apply in this case. I
could set up a Custom method and call that method instead, but it would
require some recoding, so I was wondering if the Event can be raised
directly. (I vaguely recall a way to do this, but it's evading me right
now!)

Private Sub PicBox_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PicBox.Click
'My code here.
End Sub

How do I call this method, or raise the Click event for the PictureBox ?

Thanks in advance,

Regards,

Cerebrus.
 
S

Stephany Young

As long as the sender and e arguments are of no consequence to the piece of
magic contained in 'My code here., then you can simply call:

PicBox_Click(Nothing, Nothing)

A cleaner way to deal with it though, is to seperate the desired operation
from the event handler:

Private Sub PicBoxClickHandler()
'My code here.
End sub

The 'My code here. in PicBox_Click now becomes:

PicBoxClickHandler()

which can also be called quite cleanly from anywhere that can access the
procedure.
 
C

Cerebrus99

Hi Stephany,

Thanks for your prompt response.

I tried PicBox_Click and it works fine. I was missing out something obvious
and was trying to call PicBox.Click(nothing, nothing). Didn't realize that I
should change it to PicBox_Click ! Thanks a lot.

Regards,

Cerebrus.
 
H

Herfried K. Wagner [MVP]

Stephany Young said:
As long as the sender and e arguments are of no consequence to the piece
of magic contained in 'My code here., then you can simply call:

PicBox_Click(Nothing, Nothing)

Avoid doing that! Instead, call 'PicBox_Click(Me.PixBox, EventArgs.Empty)'
or, even better, use a separate procedure (as you already described).
 

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