add click event to button in VS2k3 c#

  • Thread starter Thread starter John
  • Start date Start date
J

John

how to add an event click to button in C# using visual studio 2003

i know i can double click on the button

but is there any other way through the code?
 
You mean programmatically, at runtime?
this.Button1.Click+=new EventHandler(Button_Click);

Where Button_Click is your eventhandler for buttons. Inside the handler you
can find out which button with:

((Button)sender).ID ;

Peter
 
In your code-behind, start a new method called Button1_Click with the proper
parameters. However, this is not really any different than double-clicking
the button from the designer. So, is this what you wanted to know or are
you looking from something different?
 
Hi John,

There are several ways to add an event:

1. Double click the control: only for the default event, such as
Button_Click, DropDownList_SelectedIndexChanged,
DataGrid_SelectedIndexChanged, and so on.

2. In Page Design View, select control. Then in Properties window click
events tab (Flash sign), select an event and double click it.

3. In InitializeComponent, type controlName.eventName += (Tab Key twice)

HTH

Elton Wang
 
Tnxxxxxxxxxxx


Elton W said:
Hi John,

There are several ways to add an event:

1. Double click the control: only for the default event, such as
Button_Click, DropDownList_SelectedIndexChanged,
DataGrid_SelectedIndexChanged, and so on.

2. In Page Design View, select control. Then in Properties window click
events tab (Flash sign), select an event and double click it.

3. In InitializeComponent, type controlName.eventName += (Tab Key twice)

HTH

Elton Wang
 

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

Back
Top