0

So how to begin. I am asking when you make a game for example and you add a controlls how do I make the form's key events run when the focus isnt on the form but on some of the controlls and when i call this.Focus() or this.Select() it doesnt't happen anything, but if I use a empty form(with no controls) it works(the events respond).And when i have for example 2 buttons and call button1.focus() and press a key the button1's event handler responds (only it) adn then when i call button2.Focus() it responds for button2.How is focus distributed througt the controlls? I know for muttons you have to click them once to put the focus on them automaticly and for textboxtes too,but when i click the form it doesnt move the focus on the form.

Im have almost no experience with Key events please explayn me how to use them and how they function understandly.

PS: sorry for the long questin

4
  • Consider splitting your questions. That makes it easier to answer. Commented Aug 16, 2011 at 11:53
  • My general quetion is how they function and how to use them (the events) Commented Aug 16, 2011 at 12:00
  • Yes, I know. My recommendation still stands, because they are two separate questions that just happen to touch the same concepts. =) Commented Aug 16, 2011 at 12:01
  • ok I'll remove the part about KeyEventArgs Commented Aug 16, 2011 at 12:02

1 Answer 1

2

You can set the Form.KeyPreview to true to have the form react to key events.

Sign up to request clarification or add additional context in comments.

4 Comments

So when I set that to true and the focus is on a button or something else the form will call its event handler? And if the focus is on a button will the button call its key event handler too?
If KeyPreview is true the form first reacts to event, you still need to implement KeyDown for form or similar event.
So if i implemeted form's keyDown event and keyPreview is true and i have a buton and the focus is on that button and the button also has a different from the form's keyDonw event handler, then if i press a key first the form's event handler calls and then the button's(or other control that has focus and has a key event handler)?
I used only form keyDown event or control's keyDown and never both. But msdn says it should work. msdn.microsoft.com/en-us/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.