【问题标题】:C# WPF - OpenTK GLControl mouse eventsC# WPF - OpenTK GLControl 鼠标事件
【发布时间】:2020-02-13 15:19:41
【问题描述】:

我在 Windows 窗体主机中使用 OpenTK GLControl 设置了 WPF 项目...当我将事件绑定到 GLControl 的鼠标事件(MouseDown、MouseWheel 等)时,我无法让它们发挥作用。鼠标在 GLControl 上时完成的任何鼠标输入似乎都不会触发。有没有办法在表单主机内部的 GLControl 上完成鼠标输入?

我在使用 GLControl 加载时绑定事件

glControl1.MouseWheel += glControl1_MouseWheel; 

然后创建

private void glControl1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
    Console.WriteLine("Do something");
}

【问题讨论】:

    标签: c# wpf opentk


    【解决方案1】:

    在你的项目中添加一个用户控件,然后在 .cs 中,你有类似的东西:

    public partial class WindowGL: System.Windows.Forms.UserControl{
    
    private void mouseDown(object sender, System.Windows.Forms.MouseEventArgs e){}
    private void mouseMove(object sender, System.Windows.Forms.MouseEventArgs e){}
    private void mouseUp(object sender, System.Windows.Forms.MouseEventArgs e){}
    }
    

    然后在设计视图中将事件与函数连接起来。 在 WPF 中:

    this.diagramHost.Child = new WindowGL();
    

    见:https://kishordgupta.wordpress.com/2010/12/21/opentk-a-simple-2d-clock-design-in-windows-form-c-basic-opentk-1/

    【讨论】: