没有重载方法“OnMouseDown”有 0 个参数

发布于 2024-12-14 02:11:01 字数 411 浏览 6 评论 0原文

我试图将 winform OnMouseDown 事件设置为我定义的名为 SelectMouseDown 的方法。

该方法定义如下:

method Maker.SelectMouseDown(Sender: Object; e: System.Windows.Forms.MouseEventArgs);

并且我尝试执行以下操作:

OnMouseDown += System.Windows.Forms.MouseEventHandler(@Self.SelectMouseDown);

编译器抛出以下错误消息:“没有带有 0 个参数的重载方法“OnMouseDown”。”

我做错了什么?如何在运行时设置事件?

提前致谢,

I am trying to set winform OnMouseDown event to a method I defined called SelectMouseDown.

The method is defined as follows:

method Maker.SelectMouseDown(Sender: Object; e: System.Windows.Forms.MouseEventArgs);

and I am trying to do the following:

OnMouseDown += System.Windows.Forms.MouseEventHandler(@Self.SelectMouseDown);

The compiler throws the following error message: "There is no overloaded method "OnMouseDown" with 0 parameters."

What am I doing wrong? How do you set events during runtime?

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2024-12-21 02:11:01

您忘记了 new,该事件被命名为 MouseDown,正如 Marc Gravell 指出的那样:

MouseDown += new System.Windows.Forms.MouseEventHandler(@Self.SelectMouseDown);

我不了解 Delphi,但在 C# 中,编译器可以自动创建委托:

MouseDown += @Self.SelectMouseDown;

You forgot new, and the event is named MouseDown as Marc Gravell pointed out:

MouseDown += new System.Windows.Forms.MouseEventHandler(@Self.SelectMouseDown);

I don't know about Delphi, but in C# the compiler can create the delegate automatically:

MouseDown += @Self.SelectMouseDown;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文