简体   繁体   English

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

[英]How can I initiate mouse events in MDI?

I have MDI application where childforms contains picturebox. 我有MDI应用程序,其中子窗体包含图片框。 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. 我想在激活的(fImage activeChild = this.ActiveMdiChild as fImage;)childbox的picturebox.image中获取像素值。因此,我需要先以childform形式启动鼠标事件,然后以child以及父形式编写函数来访问这些事件事件。

// in Child form I initiated event this.pictureBox1.MouseMove +=new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); //以子形式,我启动了事件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. //我不知道子窗体中的函数应该像什么样(type,get,set)返回在pparentform中发生的鼠标事件。 Also the function a (type, get , set) in parent form to have access of these events happening in childform. 父形式的函数a(类型,get,set)也可以访问子形式发生的这些事件。 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           
}

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. 但是,如果您坚持这样做,则可以使用interop调用mouse_event。 Or calling your own private mousedown handler with reflection, but that's even worse. 或通过反射调用自己的私有mousedown处理程序,但这甚至更糟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM