这是什么Button.PerformClick办? [英] What does Button.PerformClick do?
问题描述
我知道这可能是一个微不足道的问题,但我只是想知道是否有要求的 Button.PerformClick
而不是直接调用按钮的点击事件。 MSDN文档只是说:
I know this might be a trivial question, but I was just wondering whether there is any advantage of calling Button.PerformClick
rather than invoking the click event of a button directly. The MSDN documentation simply says:
生成一个按钮点击事件。
Generates a Click event for a button.
这是否意味着它只是做同样的事情与调用按钮的点击事件或者是有一些其他的特殊优势?
Does this mean it simply does the same thing as calling the click event of the button or is there some other special advantage?
推荐答案
这是外部呼叫者谁知道什么订阅事件不能简单地调用click处理程序 - 并且事件不会让你获取有关用户的信息。因此,这种方法可以让关注点分离,使外部呼叫者可以玩好。
An external caller who knows nothing of the subscribed events cannot simply call the click handler - and events do not allow you to obtain information about subscribers. So this method allows separation of concerns, so that external callers can "play nice".
此外:
- 在它保证了在虚拟方法的任何多态性适用
- 在它适用的规则 - 例如:在按钮禁用
如果您知道有关事件的处理程序,并没有使用多态,和你不在乎它是否被禁用,而你并不需要担心的事件处理程序,你不知道的约 - 然后通过各种手段:只需要调用的事件处理程序方法
If you do know about the event-handler, and you aren't using polymorphism, and you don't care whether it is disabled, and you don't need to worry about event-handlers you don't already know about - then by all means : just call the event-handler method.
这篇关于这是什么Button.PerformClick办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!