473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling another method in C#

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

Oct 31 '07 #1
9 1993
CM,

Well, how are you trying to call it? What is the error you are getting?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CMartin" <CM*****@discussions.microsoft.comwrote in message
news:5A**********************************@microsof t.com...
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

Oct 31 '07 #2
On 2007-10-31 12:12:00 -0700, CMartin <CM*****@discussions.microsoft.comsaid:
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.
And in addition to what Nicholas wrote, what do you mean "call it"?
Even in VB, given that the method name looks a lot like an event
handler, you shouldn't be calling it explicitly. You would just
subscribe it to the Click event on the Button control in question.

You can do this explicitly in your own code using the "+" operator on
the event:

Button btn = ...;

btn.Click += buttonRun_Click();

or even better, just use the VS Designer to hook it up by assigning it
in the properties inspector for the control (you'll have to click on
the lightning-bolt button to show the events for the control).

The former is significantly different from the VB paradigm, but the
latter should be basically the same AFAIK in either language (and will
auto-generate the appropriate code, whether you're writing VB or C#).

Pete

Oct 31 '07 #3
I am sorry. For some reason I have a total brain cramp with this. ......
I am trying to in the code below have another buttons click event fired when
text is changed:
private void toolStripStatusLabel3_TextChanged(object sender, EventArgs e)
{
// here is where I want to fire the buttonRun event

}

"Peter Duniho" wrote:
On 2007-10-31 12:12:00 -0700, CMartin <CM*****@discussions.microsoft.comsaid:
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.

And in addition to what Nicholas wrote, what do you mean "call it"?
Even in VB, given that the method name looks a lot like an event
handler, you shouldn't be calling it explicitly. You would just
subscribe it to the Click event on the Button control in question.

You can do this explicitly in your own code using the "+" operator on
the event:

Button btn = ...;

btn.Click += buttonRun_Click();

or even better, just use the VS Designer to hook it up by assigning it
in the properties inspector for the control (you'll have to click on
the lightning-bolt button to show the events for the control).

The former is significantly different from the VB paradigm, but the
latter should be basically the same AFAIK in either language (and will
auto-generate the appropriate code, whether you're writing VB or C#).

Pete

Oct 31 '07 #4
If you just factor out whatever code is in the Button_Run handler into a
separate method, you can replace the // here is where i want... line with a
call to that method.
-- Peter
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"CMartin" wrote:
I am sorry. For some reason I have a total brain cramp with this. ......
I am trying to in the code below have another buttons click event fired when
text is changed:
private void toolStripStatusLabel3_TextChanged(object sender, EventArgs e)
{
// here is where I want to fire the buttonRun event

}

"Peter Duniho" wrote:
On 2007-10-31 12:12:00 -0700, CMartin <CM*****@discussions.microsoft.comsaid:
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.
And in addition to what Nicholas wrote, what do you mean "call it"?
Even in VB, given that the method name looks a lot like an event
handler, you shouldn't be calling it explicitly. You would just
subscribe it to the Click event on the Button control in question.

You can do this explicitly in your own code using the "+" operator on
the event:

Button btn = ...;

btn.Click += buttonRun_Click();

or even better, just use the VS Designer to hook it up by assigning it
in the properties inspector for the control (you'll have to click on
the lightning-bolt button to show the events for the control).

The former is significantly different from the VB paradigm, but the
latter should be basically the same AFAIK in either language (and will
auto-generate the appropriate code, whether you're writing VB or C#).

Pete
Oct 31 '07 #5
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
}
Oct 31 '07 #6
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
}
Nov 1 '07 #7
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

Nov 1 '07 #8
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();
}

Nov 1 '07 #9
Couldn't be any easier:

private void toolStripStatusLabel3_TextChanged(object sender, EventArgs e)
{
buttonRun.PerformClick();
}
"CMartin" <CM*****@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.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
}

Nov 1 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Dave Veeneman | last post by:
I'm using inheritance more than I used to, and I find myself calling a lot of base class methods. I generally call a base method from a dreived class like this: this.MyMethod(); I'm finding...
7
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
6
by: Mirek Endys | last post by:
Hello all, another problem im solving right now. I badly need to get typeof object that called static method in base classe. I did it by parameter in method Load, but i thing there should be...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.