Winforms events help
Winforms events help
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!.
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!.
Ok so far im guessing i need to implement the interface
Next i need to access the OnEvent from the WorldEvents class within my main class..
Code: Select all
public class WorldEvents : IEventReceiver
{
public WorldEvents()
{
}
public bool OnEvent(Irrlicht.Event evt)
{
return true;
}
}
ok so in my main class i add
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?
Code: Select all
WorldEvents MyEvents = new WorldEvents();
device.EventReceiver = MyEvents;
my code never seems to go to OnEvent in my other class.. i thought thats how it was supposed to work! ? any ideas?
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.
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.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 } }
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
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");
}
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
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.
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.