Hi all,
I want to raise the event click of a control by code. How can i do that ??

Re: how to raise the click event by code by GM3TEN

GM3TEN
Tue May 09 12:15:57 CDT 2006

Hi Fanor,

If your control derives from either UserControl or Control you can call
the protected OnClick method from within your control's definition:

this.OnClick(EventArgs.Empty);

or, in the case you need to make this method public to consumers of
your control you can expose a public interface to the protected
"OnClick" method (the Button control already does this):

public void PerformClick()
{
this.OnClick(EventArgs.Empty);
}

Additionally, you can override the OnClick method in your derived
control's implementation (so your control can process other things
before raising the "Click" event).

protected override void OnClick(EventArgs e)
{
//do something here before calling the base OnClick() method to
raise the click event.
base.OnClick (e);
}


-GM
http://nonspect.com


Fanor wrote:
> Hi all,
> I want to raise the event click of a control by code. How can i do that ??


Re: how to raise the click event by code by Markus

Markus
Tue May 09 12:21:28 CDT 2006

> public void PerformClick()
> {
> this.OnClick(EventArgs.Empty);
> }

And if you already have a System.Windows.Forms.Button control, then a
public PerformClick() method is already available.

Markus

Re: how to raise the click event by code by Fanor

Fanor
Tue May 09 12:45:48 CDT 2006

Thanks guys,

But my problem is a bit different. Usually the click event is raised when
the user push a mouse button, what I want to do is to send this "click" by
code to a button control in order to raise the click event of that button.

TIA


"GM3TEN" <gmunday310@hotmail.com> wrote in message
news:1147194957.736213.101060@y43g2000cwc.googlegroups.com...
> Hi Fanor,
>
> If your control derives from either UserControl or Control you can call
> the protected OnClick method from within your control's definition:
>
> this.OnClick(EventArgs.Empty);
>
> or, in the case you need to make this method public to consumers of
> your control you can expose a public interface to the protected
> "OnClick" method (the Button control already does this):
>
> public void PerformClick()
> {
> this.OnClick(EventArgs.Empty);
> }
>
> Additionally, you can override the OnClick method in your derived
> control's implementation (so your control can process other things
> before raising the "Click" event).
>
> protected override void OnClick(EventArgs e)
> {
> //do something here before calling the base OnClick() method to
> raise the click event.
> base.OnClick (e);
> }
>
>
> -GM
> http://nonspect.com
>
>
> Fanor wrote:
>> Hi all,
>> I want to raise the event click of a control by code. How can i do that
>> ??
>



Re: how to raise the click event by code by GM3TEN

GM3TEN
Tue May 09 12:58:28 CDT 2006


...myButton.PerformClick();


Fanor wrote:
> Thanks guys,
>
> But my problem is a bit different. Usually the click event is raised when
> the user push a mouse button, what I want to do is to send this "click" by
> code to a button control in order to raise the click event of that button.
>
> TIA
>
>
> "GM3TEN" <gmunday310@hotmail.com> wrote in message
> news:1147194957.736213.101060@y43g2000cwc.googlegroups.com...
> > Hi Fanor,
> >
> > If your control derives from either UserControl or Control you can call
> > the protected OnClick method from within your control's definition:
> >
> > this.OnClick(EventArgs.Empty);
> >
> > or, in the case you need to make this method public to consumers of
> > your control you can expose a public interface to the protected
> > "OnClick" method (the Button control already does this):
> >
> > public void PerformClick()
> > {
> > this.OnClick(EventArgs.Empty);
> > }
> >
> > Additionally, you can override the OnClick method in your derived
> > control's implementation (so your control can process other things
> > before raising the "Click" event).
> >
> > protected override void OnClick(EventArgs e)
> > {
> > //do something here before calling the base OnClick() method to
> > raise the click event.
> > base.OnClick (e);
> > }
> >
> >
> > -GM
> > http://nonspect.com
> >
> >
> > Fanor wrote:
> >> Hi all,
> >> I want to raise the event click of a control by code. How can i do that
> >> ??
> >


Re: how to raise the click event by code by Stoitcho

Stoitcho
Thu May 11 09:29:44 CDT 2006

Fanor,

Try Control.InvokeOnClick method.

It is protected method of the Control class, so it needs to be called from a
class that derives from a Control. However using this method you can raise
Click event on any other control.


--
HTH
Stoitcho Goutsev (100)

"Fanor" <xreed2000@yahoo.com> wrote in message
news:OOgjoZ4cGHA.4264@TK2MSFTNGP05.phx.gbl...
> Hi all,
> I want to raise the event click of a control by code. How can i do that ??
>