Firing Events

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.
 
C

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( .. );
}
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

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
 
V

Val Savvateev

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));

}

}
 

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