Eackz's picture

OpenTK MouseDown event not working :(

Hello, I am creating a program in C# with OpenTK, and I am trying to dynamically add an openTk control, with a mouseDown event.

for some reason, the mouseDown event does not respond.

Here is my code:

    public partial class Form1 : Form
    {
        OpenGL3 openGl3Control;
        bool openGLLoaded;
 
        public void openGL3Control_MouseClick1(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            MessageBox.Show("Derp");
        }
 
        public Form1(string xmlURL)
        {
            InitializeComponent();
            openGl3Control = new OpenGL3();
 
            //Add The Custom OpenGL Control to the large panel in the Upper Left.
            splitContainer3.Panel1.Controls.Add(openGl3Control);
            openGl3Control.MouseDown += new MouseEventHandler(this.openGL3Control_MouseClick1);
 
        }...

Any help would be greatly appreciated :)


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

This is a plain WinForms MouseDown event, OpenTK does not affect it in any way.

Make sure your control is first in the z-order (use BringToFront if necessary).

Eackz's picture

Ok, well I used BringToFront(), and I don't know what event to use to detect for mouse being clicked. So, what code do I use?

winterhell's picture

OpenTK.Input.MouseDevice md = new OpenTK.Input.MouseDevice();
then md.ButtonDown is for an event and if(md[OpenTK.Input.MouseButton.Left]){...} for checking if the left mouse is pressed

Eackz's picture

Ok, well how do I set the event for mouse input? I'm not running a while loop or anything like that so I cannot constantly check if a mouse input is occuring. I need there to be an event listener for when the mouse is clicked inside my 3D view. I am trying to build a level editor. Please, I need to know how to do this. Some code examples would really help. Thanks.

Eackz's picture

Update: Alright, I got the event to be added, but the event does not respond. I am using Windows 8. What do I do now? Here is my code:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        MouseDevice mouseDevice;
        OpenGL3 openGl3Control;
        //Panel mouseInputWorkAround;
 
        public void openGL3Control_MouseClick1(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Derp");
        }
 
        public Form1(string xmlURL)
        {
            //this.MouseDown += new MouseEventHandler(openGL3Control_MouseClick1);
            mouseDevice = new MouseDevice();
            mouseDevice.ButtonDown += new EventHandler<MouseButtonEventArgs>(openGL3Control_MouseClick1);
            //mouseDevice.ButtonDown += new EventHandler(openGL3Control_MouseClick1);
            xmlObjectsList = xmlURL;
            InitializeComponent();
            openGl3Control = new OpenGL3(); ...