Winforms events help

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Winforms events help

Post 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!.
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post 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..
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post 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?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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
        }
}
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post 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 :)
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post 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.
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post by TOP-Proto »

i am gonna have another bash at this soon, but any ideas anyone?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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");
		}

TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post 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?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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.
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post 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:
matiae
Posts: 16
Joined: Wed May 31, 2006 8:06 am
Location: Chile

Post by matiae »

michael520 wrote: I suggest that niko or afecis should add solutions for this questions to the wiki. :wink:
I have to agree.. :?
Locked