please how do i handle an event with two buttons like in vb.net.
that is i have a code under one event and i want to be able to run this same code with the click on another button on the same form. I know how to do this in vb.net but i do not know how to do this in c#.Please help me
because i do not want to duplicate code.
4 Replies - 363 Views - Last Post: 12 August 2011 - 07:14 AM
#1
Event Handler(Run the same codes with two buttons)
Posted 12 August 2011 - 06:42 AM
Replies To: Event Handler(Run the same codes with two buttons)
#2
Re: Event Handler(Run the same codes with two buttons)
Posted 12 August 2011 - 06:48 AM
So this is a C# question and not a VB.NET? Moving accordingly.
#3
Re: Event Handler(Run the same codes with two buttons)
Posted 12 August 2011 - 06:56 AM
Assign the same method to the click event handler, just like you'd do in VB.NET.
#4
Re: Event Handler(Run the same codes with two buttons)
Posted 12 August 2011 - 07:07 AM
Momerath, on 12 August 2011 - 06:56 AM, said:
Assign the same method to the click event handler, just like you'd do in VB.NET.
Please can you explain further
i dont really understand what you mean
I vb.net you can have the eg.Button click event there with its code inside and so at where we can have the handle buttonI.click you can just type, button2.click
i this case it means button2 can run the same code under button1.This is what i want to do
#5
Re: Event Handler(Run the same codes with two buttons)
Posted 12 August 2011 - 07:14 AM
Ugh.. okay. In your designer... click on your button1. Show the events in the property pane. Go to the click event. Select your method for the click event. Now click button2. Show the events in the property pane. Go to the click event. Select that same method for the click event.
Alternative.
In your form's constructor add the same event handler to each button's click event. This is assuming you have a proper click method already written called 'button2_click'.
Alternative.
In your form's constructor add the same event handler to each button's click event. This is assuming you have a proper click method already written called 'button2_click'.
button1.Click += new EventHandler(button2_Click); button2.Click += new EventHandler(button2_Click);
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|