Windows form with mouse inputs example - solved

zorocke

11-04-2010 17:02:39

There are 3 edits to this post that i added as i progressed on this problem. Please feel free to skip closer to the bottom for the most recent problem.

I've been trying to get my windows form application to work with any kind of input system. I've tried OIS and winform input. But i'm still stuck at getting anything to work correctly.

I'm using the windows form example that comes with MOGRE as the basis of my code and trying to add input to this application.

Does anyone happen to have an example that uses windows form and input without using a framelistener? preferably one that works with mouse movement into and out of the mogre panel.

I haven't been able to get the tutorial to work... and i'm not exactly sure why. I'll try messing with it some more to see if i can provide a more detailed description of where it fails.

[edit]
Ignore this, i fixed this problem
Okay, so i added this code to my Form's class.
I put this in the constructor.
this.KeyDown += new KeyEventHandler(KeyDownHandler);
this.KeyUp += new KeyEventHandler(KeyUpHandler);


and then added these methods
void KeyDownHandler(object sender, KeyEventArgs e)
{

switch (e.KeyCode)
{
case Keys.Up:
case Keys.W:
MessageBox.Show("Ummm works?");
break;

case Keys.Down:
case Keys.S:
//mTranslation.z = TRANSLATE;
break;

case Keys.Left:
case Keys.A:
// mTranslation.x = -TRANSLATE;
break;

case Keys.Right:
case Keys.D:
// mTranslation.x = TRANSLATE;
break;

case Keys.PageUp:
case Keys.Q:
// mTranslation.y = TRANSLATE;
break;

case Keys.PageDown:
case Keys.E:
// mTranslation.y = -TRANSLATE;
break;
}

}
void KeyUpHandler(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
case Keys.W:
case Keys.Down:
case Keys.S:
//mTranslation.z = 0;
break;

case Keys.Left:
case Keys.A:
case Keys.Right:
case Keys.D:
// mTranslation.x = 0;
break;

case Keys.PageUp:
case Keys.Q:
case Keys.PageDown:
case Keys.E:
// mTranslation.y = 0;
break;
}
}


But when i press W, nothing is happening.

[edit number 2! -- ignore this and move to edit number 3]
okay, i've solved the keyboard problem. I needed to add the line this.KeyPreview = true; I don't understand why that is, but it works. so i wont complain.

anyway, now i'm stuck getting mouse input to work..

I added
this.MouseUp += new MouseEventHandler(OnMouseup); to the form's constructor. then added
public void OnMouseup(object sender, MouseEventArgs e)
{
MessageBox.Show( e.X + " , " + e.Y);
this.Text = "Current Position (" + e.X + " , " + e.Y + ")";
}


This code works if I release the mouse button when the my mouse is not over the mogre panel(or any other panel for that matter). Any ideas, i'm guessing it's probably something simple that i overlooked?

[EDIT number 3 now!! - solved also now] :)

Okay so after some research on the forums, i found that i need to subscribe to the panels mouse move event possibly or something like that?

So i tried adding mogrePanel.MouseMove += new MouseEventHandler(Form1_MouseMove); and
// This method gets called when the mouse moves.
void Form1_MouseMove(object sender, MouseEventArgs e)
{
//labelMousePosition.Text = "Mouse Position: X: " + e.X + " Y: " + e.Y;
}


But this for some reason gives
Error 1 The event 'System.Windows.Forms.Control.MouseMove' can only appear on the left hand side of += or -= C:\Documents and Settings\steven\My Documents\My Dropbox\D-Race\LevelEditor\LevelEditor\Form1.cs 49 24 LevelEditor


Any help here? -- Okay, so the problem was something with "+=" i had copied that code off the internet. i'm not sure what was wrong with it, but when i rewrote += it worked.

sorry this post keeps getting longer and longer as i dive deeper into my task.