Skip to main content
gamedev.net
🔒 Locked

[.net] Focus Problem

Started by Shurijo Aug 28, 2005 at 7:21 PM 0 replies 500+ views
Original Post
Shurijo
Shurijo
Here is my problem: I am using a 3D component (Irrlicht) to render to a Windows Form background. This works perfectly as is. This component has an event receiver that also works (for mouse clicks and keypress down/up). However, when I click on a winform control (button), the focus goes to the control and my keypress events are not sent to the component. The keypress events are sent to the control’s keypress event. My mouse click events on the form’s background still sends an event to the component. All of my controls have the tabstop=false. I have tried adding this.show(), this.activate(), this.focus(), this.select() (this=win form) to the control’s onclick event. I have even added code to set the clicked control enable=false and visible=false (in hopes of losing focus), but it still retains the focus. If I put a MessageBox.Show() on the onclick event, then the control’s focus is removed and my events are sent to the component’s keypress (it works). On the initial form load, both mouse and keypress events are sent to the component perfectly, it is when I interact with the form controls that the focus changes and I cannot set it back to the form. So in summary: Form load – component receives keypress events (works) Click on control – component receives no keypress events (doesn’t work) Click on control with MessageBox.Show() - component receives keypress events (works) I need a way to lose focus to everything on the form and get back to the state of initial form load - a “blur” (&#106avascript) like command for winforms. Thanks,
Shurijo
Shurijo
Ok, figured it out, but if there's a better way let me know:

I enabled keypreview on form to capture all keyevents before the form's child controls get the event. Now, I have two separate keypress receivers- 1 for the form and 1 for the component, so I created a static bridge "commandhandler" class which both receivers call to perform the actual game action. In the form's keypress event (which is called before the focused control's keypress event because of keypreview=true), I bypass the component's event handler and send the keydata to a new "commandhandler" class.




Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.