如何在 MDI 中启动鼠标事件?

发布于 2024-10-09 19:29:35 字数 602 浏览 0 评论 0原文

我有 MDI 应用程序,其中子窗体包含图片框。我想获取activated (fImage activeChild = this.ActiveMdiChild as fImage;) childform的picturebox.image中的像素值。所以我需要首先在子窗体中启动鼠标事件,然后在子窗体和父窗体中编写函数来访问这些函数事件。

// 在子窗体中我发起了事件 this.pictureBox1.MouseMove +=new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);

// 我不知道子窗体中的函数应该是什么样子(类型、获取、设置)来返回父窗体中发生的鼠标事件。父窗体中的函数 a (type, get , set) 也可以访问子窗体中发生的这些事件。有什么建议吗???

public float pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    x = e.X;
    y = e.Y;

    // not clear how to code it           
}

I have MDI application where childforms contains picturebox. I want to get pixel value in picturebox.image of activated (fImage activeChild = this.ActiveMdiChild as fImage;) childform.So I need to initiate mouse events first in childform and then write functions in child as well as in parent form to access these events.

// in Child form I initiated event
this.pictureBox1.MouseMove +=new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);

// I don't have idea what should my function in childform looklike ( type,get, set)to return me mouse event that is happening in pparentform. Also the function a (type, get , set) in parent form to have access of these events happening in childform. Any suggestion plaese???

public float pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    x = e.X;
    y = e.Y;

    // not clear how to code it           
}

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

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

发布评论

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

评论(1

沫尐诺 2024-10-16 19:29:35

您应该在子表单中提供一个公共方法来执行您想要的操作,并且父级可以调用它。它更好、更简单、更干净。在任何方面都优于操作鼠标事件。不过,如果您坚持这样做,您可以通过互操作调用 mouse_event。或者通过反射调用您自己的私有 mousedown 处理程序,但这更糟糕。

You should provide a public method in your child form which does what you want and the parent can call this. It is better, simpler, cleaner. Superior in any way to manipulating mouse events. If you insist on that, though, you can call mouse_event with interop. Or calling your own private mousedown handler with reflection, but that's even worse.

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