Re: Calling another method in C#

by Marc Gravell on 10/31/2007 10:54:00 PM First off - you can simply set the toolStripStatusLabel3.TextChanged
event to fire buttonRun_Click; either in the IDE by using the pull-
down menu, or through code:
toolStripStatusLabel3.TextChanged += buttonRun_Click;

As for the specific question - you need to give it the args; try:
buttonRun_click(sender, e);

But if that is *all* that toolStripStatusLabel3_TextChanged does, then
the first (shared handler) approach is simpler.

Marc

 

Re: Calling another method in C#

by Marc Gravell on 10/31/2007 10:57:00 PM > buttonRun_click(sender, e);

or, clearer:

private void DoSomethingIntersting() {
 // ...common code
}
private void buttonRun_Click(object sender, EventArgs e) {
  // ...code specific to buttonRun
  // then:
  DoSomethingIntersting();
}
private void toolStripStatusLabel3_TextChanged(object sender,
EventArgs e) {
  // ...code specific to toolStripStatusLabel3
  // then:
  DoSomethingIntersting();
}

 

Re: Calling another method in C#

by Mindgeek on 11/1/2007 7:15:00 AM Couldn't be any easier:

private void toolStripStatusLabel3_TextChanged(object sender, EventArgs e)
{
       buttonRun.PerformClick();
}


"CMartin" <CMartin@discussions.microsoft.com> wrote in message
news:9B4C5C63-530A-4C34-8820-8142307D10BB@microsoft.com...
>I have a lot of code in this button click event:
> private void buttonRun_Click(object sender, EventArgs e)
>
> Now I want to trigger that event above when someting happens in this text
> changed event:
> private void toolStripStatusLabel3_TextChanged(object sender, EventArgs
> e)
>
> I just do not understand whi I cannot simply invoke the button_click
> routine. liek below:
> private void toolStripStatusLabel3_TextChanged(object sender, EventArgs
> e)
> {
> buttonRun_click():
> }
>
> But it does not liek it and I am very confused. In VB, this was soooo
> easy.
>
>
> "j1mb0jay" wrote:
>
>> CMartin wrote:
>> > How do I call the "buttonRun_Click()" method in C#?
>> >
>> > I can do this so easily in VB but I have yet to figuere out how in C#.
>> > I
>> > keep getting errors.
>> >
>> > Thanks
>> > CM
>> >
>>
>> Why dont you put the code in button event method into a different method
>> and then call this new method when the button event is fired. You can
>> then call the new method from anywhere in the class, or if you make it
>> public from anywhere.
>>
>> buttonRun_Click()
>> {
>> NewMethod();
>> }
>>
>> private void NewMethod()
>> {
>> blar blar
>> }
>>