Page 1 of 1

Winforms events help

Posted: Mon Jul 17, 2006 5:56 pm
by TOP-Proto
Hi guys, im fumbling about at this, and i have come across the events problem with winforms.

All i want to do is capture my events (keyboard, mouse, gui) but i dont know too much about events and delegates.

How do i capture these events? if someone can point me in the right direction i can continue with my project.

ta!.

Posted: Mon Jul 17, 2006 6:32 pm
by TOP-Proto
Ok so far im guessing i need to implement the interface

Code: Select all

	public class WorldEvents : IEventReceiver
	{
		public WorldEvents()
		{
		}
		public bool OnEvent(Irrlicht.Event evt) 
		{ 
			return true;
		}
                    }
Next i need to access the OnEvent from the WorldEvents class within my main class..

Posted: Mon Jul 17, 2006 7:20 pm
by TOP-Proto
ok so in my main class i add

Code: Select all

			WorldEvents MyEvents = new WorldEvents();
			device.EventReceiver = MyEvents;
now shouldnt it just capture events?
my code never seems to go to OnEvent in my other class.. i thought thats how it was supposed to work! ? any ideas?

Posted: Mon Jul 17, 2006 10:52 pm
by shurijo
Are you trying to capture events from the WinForm or from the Irrlicht Device?

Are you displaying the IrrlichtDevice within a WinForm (like on the form's background or picture box) or in its own window?

If you are opening IrrlichtDevice in its own window and capturing events, just follow the tutorial #5.

You need to implement the interface's method. If you just use OnEvent, then you are overloading instead of overriding.

Code: Select all

public class EventReceiver : IEventReceiver
    {
        public EventReceiver()
        {
        }
        bool IEventReceiver.OnEvent(Irrlicht.Event e)
        {
        //do stuff
        }
}

Posted: Tue Jul 18, 2006 7:27 am
by TOP-Proto
i am using a picturebox on my winform. i am trying to capture the device events.

I will try that code when i get home :)

Posted: Tue Jul 18, 2006 7:35 am
by TOP-Proto
shurijo wrote:Are you trying to capture events from the WinForm or from the Irrlicht Device?

Are you displaying the IrrlichtDevice within a WinForm (like on the form's background or picture box) or in its own window?

If you are opening IrrlichtDevice in its own window and capturing events, just follow the tutorial #5.

You need to implement the interface's method. If you just use OnEvent, then you are overloading instead of overriding.

Code: Select all

public class EventReceiver : IEventReceiver
    {
        public EventReceiver()
        {
        }
        bool IEventReceiver.OnEvent(Irrlicht.Event e)
        {
        //do stuff
        }
}
this code doesnt seem to work on my winform though. how do i capture events? basically i want my picbox to intercept my mouse calls, and keyboard calls.

Posted: Tue Jul 18, 2006 5:44 pm
by TOP-Proto
i am gonna have another bash at this soon, but any ideas anyone?

Posted: Wed Jul 19, 2006 2:25 am
by shurijo
If any control on the WinForm has focus, then *ALL* events are sent to the WinForm and not Irrlicht Device. Odds are, all of your events are being handled by the WinForm event handler and never passed to IrrlichtDevice. I had that same problem before and I had to convert my GUI to a IrrlichtDevice window (instead of WinForm) due to the complicate event handling (having to handle events from WinForm mostly, and IrrlichtDevice to start).

Add a On KeyPress event to your form to see if your WinForm is capturing your events instead of the IrrlichtDevice

Code: Select all

	private void frmGameGUI_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			this.ConsoleWrite(e.KeyChar.ToString() + " keypressed");
		}


Posted: Fri Jul 21, 2006 12:06 am
by TOP-Proto
sigh nothing happened at all! :/

All i wanna do is capture irr events, how come its not so easy in a winform?

Posted: Fri Jul 21, 2006 4:55 am
by shurijo
TOP-Proto wrote:sigh nothing happened at all! :/

All i wanna do is capture irr events, how come its not so easy in a winform?
Its because your events are being captured by the WinForm.

Posted: Wed Jul 26, 2006 7:21 am
by michael520
guys, all events are handled by Irrlicht!

Irrlicht will send the event to your EventReceiver(If you set one), and then send to GUIEnvironment, then SceneManager.

and, if any key or mouse events are absorbed, they wouldn't be send to the later.


///////////////////////////////
In Win32 way, you may customize the WindowProc youself, and process all commands by command id.

///////////////////////////////
I don't know how to process this if using a dot net winform, in your own EventReceiver, OnEvent method, you should do all things for those messages. If you have set delegate for a button in the form, I don't know if it will be access when pressing the button.

/////////////////////////////

I suggest that niko or afecis should add solutions for this questions to the wiki. :wink:

Posted: Thu Aug 03, 2006 7:48 am
by matiae
michael520 wrote: I suggest that niko or afecis should add solutions for this questions to the wiki. :wink:
I have to agree.. :?