Jump to content
  • Advertisement
Sign in to follow this  
Shurijo

[.net] Focus Problem

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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” (javascript) like command for winforms. Thanks,

Share this post


Link to post
Share on other sites
Advertisement
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.




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!