Winform KeyPress
-
I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,
-
I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,
-
I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,
The form has a KeyPreview property. Set that to true and you form Key handlers will get first crack at the keystrokes before any controls on it do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
The keypress event will only be triggered if the form has focus. if you want other controls to perform the same function then you must use there keypress events too.
Life goes very fast. Tomorrow, today is already yesterday.
And if you have some 30 controls on a form?? Your solution doesn't sound like a good method to me.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
And if you have some 30 controls on a form?? Your solution doesn't sound like a good method to me.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Yeah I see your point, I was thou more concerned on saying why it wasn't working rather than giving a solution, yet one made its way in :) Thou I suppose it depends on the usage, perhaps two different text boxes need to do two different things when the 'Enter' key is pressed. Sure you can check focus on the form's preview event, but then what if you want to process a textbox after input, to validate its contents for example (although I already thought you can calculate new value from key press) anyway, is circumstantial, that' all i'm saying ;)
Life goes very fast. Tomorrow, today is already yesterday.
-
The form has a KeyPreview property. Set that to true and you form Key handlers will get first crack at the keystrokes before any controls on it do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,