0

I have a program that uses OpenTk.GLControl. Now on my listener, every time the mouse hovers to the said control, say "glControl1", I want to get the mouse coordinates.

Is that possible? sample code below.

private void glControl1_MouseHover(object sender, EventArgs e)
{
    // get the current mouse coordinates       
    // .........
}
STLDev
  • 5,950
  • 25
  • 36
RJ Uy
  • 377
  • 3
  • 10
  • 20

3 Answers3

2

OpenTK.GLControl inherits from System.Windows.Forms.Control. You can use the following code snippet to get the mouse position:

private void glControl1_MouseHover(object sender, EventArgs e)
{
    Control control = sender as Control;
    Point pt = control.PointToClient(Control.MousePosition);
}

Please refer to the MSDN WinForms documentation for more information.

The Fiddler
  • 2,726
  • 22
  • 28
  • Use the MouseMove event instead. This gives you the local coordinate of the mouse pointer in the e parameter. – TomXP411 Sep 30 '13 at 23:57
1

The problem is that you're using the wrong event. Many UI actions in WinForms trigger multiple events per action; Hover is used for things like popping up tooltips. You don't get a coordinate in Hover because it's unnecessary.

What you want is the MouseMove event. This is used to track the mouse position:

    private void glControl1_MouseMove(object sender, MouseEventArgs e)
    {
        foo = e.X;
        bar = e.Y;
    }
TomXP411
  • 899
  • 9
  • 14
0

I dont know, what is OpenTk.GLControl, but:

I was handling swipe events on Windows Phone and did this:

private void PhoneApplicationPage_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        //string to save coordinates of tap
        TapCoordinatesXBegin = e.GetPosition(LayoutRoot).X.ToString();
        TapCoordinatesYBegin = e.GetPosition(LayoutRoot).Y.ToString();
    }

And i dont remember such event MouseHover - maybe MouseEnter?

Developer
  • 4,158
  • 5
  • 34
  • 66