![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Unverified User
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0
![]() |
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: . |
|
|
|
|
|
#2 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
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
__________________
Quote:
|
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Feb 2007
Posts: 3
Rep Power: 0
![]() |
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(); } |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
Even better. More descriptive.
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Unverified User
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0
![]() |
Thanks everyone, i got it work
.I already love this forum :p . |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help me fix this code please | hervens48 | Existing Project Development | 10 | Jun 18th, 2006 9:20 AM |
| Problem Associated with Vector Source code | buggytoast | Java | 3 | Apr 2nd, 2006 5:41 AM |
| IE and dynamic button creation | MegaArcon | JavaScript and Client-Side Browser Scripting | 5 | Dec 6th, 2005 8:31 AM |
| move program console window back | badbasser98 | C++ | 21 | Oct 18th, 2005 2:02 PM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |