Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 6th, 2007, 3:27 PM   #1
J-V
Unverified User
 
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0 J-V is on a distinguished road
Arrow 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: .
J-V is offline   Reply With Quote
Old Feb 6th, 2007, 3:41 PM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
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:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Feb 6th, 2007, 4:24 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Feb 7th, 2007, 6:05 AM   #4
r30
Newbie
 
Join Date: Feb 2007
Posts: 3
Rep Power: 0 r30 is on a distinguished road
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();
}
r30 is offline   Reply With Quote
Old Feb 7th, 2007, 9:21 AM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Feb 7th, 2007, 12:15 PM   #6
J-V
Unverified User
 
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0 J-V is on a distinguished road
Thanks everyone, i got it work .
I already love this forum :p .
J-V is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC