Firing Events

  • Thread starter Thread starter Christian
  • Start date Start date
C

Christian

Hi NG
maybe it's a silly question
if i have 2 buttons on a Windows Form,
button1 and button2:
button1 has delegates subscribed

this.button1.Click += new EventHandler(this.MethodA);
this.button1.Click += new EventHandler(this.MethodB);
.... // etc etc
i register a method to the Click even delegate
this.button2.Click += new EventHandler(this.RaiseClick);
In RaiseClick method a'd like to fire button1.Click event; how to?

private void RaiseClick( object sender, EventArgs e )
{
// Something like that
button1.Click( sender, e ); --> not accessible
}
( Well, i know that i have to manipulate sender and e, but it's not a
problem )

Thanks: Christian.
 
how about this.button1_click(this,new Eventargs)
what is button1_click? a method ?
I have e general button, i don't know which are the methods subscribed to
its Click Event...
Think i have e method:
public void RayseClick( Button bn ){
bn.Click( .. );
}
 
Hi Christian,
Hi NG
maybe it's a silly question
if i have 2 buttons on a Windows Form,
button1 and button2:
button1 has delegates subscribed

this.button1.Click += new EventHandler(this.MethodA);
this.button1.Click += new EventHandler(this.MethodB);
... // etc etc
i register a method to the Click even delegate
this.button2.Click += new EventHandler(this.RaiseClick);
In RaiseClick method a'd like to fire button1.Click event; how to?

private void RaiseClick( object sender, EventArgs e )
{
// Something like that
//> button1.Click( sender, e ); --> not accessible

button1.PerformClick();
}
( Well, i know that i have to manipulate sender and e, but it's not a
problem )

Thanks: Christian.

Regards

Marcin
 
Well, you could inherit from Button class and provide a way to invoke
protected method OnMouseDown through a new public method. The problem with
firing this event - you'll have to fake the event arguments (since no actual
event is happening). For instance:

public class MyButton : Button

{

public void OnMouseDown()

{

base.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));

}

}
 
Back
Top