![]() |
A Button That Activates The Other Buttons Code
Title is little bit confusing :p . Lets say i have a BUTTON1 that have much code in it and i want to make a BUTTON2 somewhere in my form, but BUTTON2 have to do the same thing that BUTTON1 does. One option is to write same code to BUTTON2 as BUTTON1 has, but it takes time :( . Is it possible to make BUTTON2 without typing again the same code, like shortcut or something?
My first post :banana: . |
i havent't done any c#, but i think that language has functions so just put your code that is inside button1 into a function/procedure then call that function/procedure when ever you need to perform that task.
Edit: or you could call button1s procedure instead of doing suggested above |
A copy-and-paste isn't very time consuming, but why edit the code in two locations?
In the click event of Button2, have it call Button1's click event function. |
private void doThisStuff()
{ int i = 0; string str = "All your commands can go here."; } private void button1_Click(object sender, EventArgs e) { doThisStuff(); } private void button2_Click(object sender, EventArgs e) { doThisStuff(); } |
Even better. More descriptive. :)
|
Thanks everyone, i got it work :) .
I already love this forum :p . |
| All times are GMT -5. The time now is 1:43 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC