Home All Groups Group Topic Archive Search About

Invoking a PictureBox click ?

Author
15 Feb 2006 9:46 AM
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.

Author
15 Feb 2006 10:02 AM
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.


Show quoteHide quote
"Cerebrus99" <zorg***@sify.com> wrote in message
news:OzINTShMGHA.1424@TK2MSFTNGP12.phx.gbl...
> 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.
>
>
Author
15 Feb 2006 10:15 AM
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.

Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:OZEwfbhMGHA.720@TK2MSFTNGP14.phx.gbl...
> 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.
>
>
> "Cerebrus99" <zorg***@sify.com> wrote in message
> news:OzINTShMGHA.1424@TK2MSFTNGP12.phx.gbl...
> > 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.
> >
> >
>
>
Author
15 Feb 2006 2:58 PM
Herfried K. Wagner [MVP]
"Stephany Young" <noone@localhost> schrieb:
> 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).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>