另一个按钮中的通话按钮 [英] call button in another button

查看:81
本文介绍了另一个按钮中的通话按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用Button中的另一个按钮?

How is that a call to another button in the Button?

推荐答案

问题的两个部分都不正确.没有呼叫按钮"这样的概念.您只能调用一个方法/函数/过程,甚至可以调用一个属性(是的,通过读取/赋值的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.


这篇关于另一个按钮中的通话按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆