Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How is that a call to another button in the Button?
Posted
Updated 18-Dec-11 0:46am
v2

Both parts of the question is incorrect. There is no such concept as "call a button". You can call only a method/function/procedure, even a property (yes, getter/setter by reading/assigning), nothing else. You cannot even "call" a .NET delegate (almost; you can invoke it which is not exactly the same, functionally). Nothing else.

Also, you cannot call anything "in a button". Controls don't have a scope for code.

As a very general suggestion, you should try to isolate UI from functionality.

—SA
 
Share this answer
 
Comments
Wendelius 18-Dec-11 14:40pm    
Exactly, 5'd
Sergey Alexandrovich Kryukov 18-Dec-11 14:43pm    
Thank you, Mika.
--SA
You can for example call the eventhandler of another button. For example in the simplest form:
C#
button1_Click(null, null);

However, I wouldn't advice this approach, instead separate the logic in a method to the same or another class and call this method from both buttons.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Dec-11 14:35pm    
I voted 4. I would not recommend even that. In you last sentence, did you mean "not advice"?

I think my "negative" answer is more accurate, will you please take a look?
--SA
Wendelius 18-Dec-11 14:40pm    
Thanks for pointing that out. The sentence didn't make any sense since it should have been "wouldn't", now corrected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900