如何在 MDI 中启动鼠标事件?
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在子表单中提供一个公共方法来执行您想要的操作,并且父级可以调用它。它更好、更简单、更干净。在任何方面都优于操作鼠标事件。不过,如果您坚持这样做,您可以通过互操作调用 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.