gpt4 book ai didi

c# - 如何引发 MouseClick 事件?

转载 作者:行者123 更新时间:2023-11-30 14:17:51 26 4
gpt4 key购买 nike

你好我读过可以像方法一样引发事件。嗯,它适用于我的自定义事件(我创建了一个委托(delegate),事件,我可以通过调用它来引发事件)。但是,我无法手动引发 MouseClick 等事件,它一直说它必须出现在 += 运算符的左侧。有什么问题?

最佳答案

虽然我确信您会得到比这个答案更丰富的其他答案,但基本上您不能在包含它的类之外“引发”事件。 MSDN 有 this to say关于事件

Events are a special kind of multicast delegate that can only be invoked from within the class or struct where they are declared (the publisher class). If other classes or structs subscribe to the event, their event handler methods will be called when the publisher class raises the event.

如果您想真正引发事件,例如,Windows 窗体控件鼠标点击,您必须创建该控件的子类并调用 base.OnMouseClick() 或覆盖它。

关于c# - 如何引发 MouseClick 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com