且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

另一个按钮中的通话按钮

更新时间:2023-01-08 08:17:01

问题的两个部分都不正确.没有呼叫按钮"这样的概念.您只能调用一个方法/函数/过程,甚至可以调用一个属性(是的,通过读取/赋值的getter/setter),而不能调用其他任何东西.您甚至无法调用" .NET委托(几乎;您可以调用功能上并不完全相同的.NET委托).没什么.

同样,您不能在按钮中"调用任何东西.控件没有代码范围.

作为一个非常普遍的建议,您应该尝试将UI与功能隔离.

—SA
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


例如,您可以调用另一个按钮的事件处理程序.例如,以最简单的形式:
You can for example call the eventhandler of another button. For example in the simplest form:
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.