WinForms Question

  • Thread starter Thread starter Jake
  • Start date Start date
J

Jake

Hi,

I am having a problem capturing a key event in a form. The problem I am
running into is on a form that returns a dialog result (OK or Cancel which
represented by two buttons) and I am trying to capture the enter key event
in a certain textbox on this form. Hwoerver the enter key returns the
dialog result because the OK button has focus (not input focus). I have
tried to capture the keydown event for the textbox and the form and it never
fires that event. Any ideas?

Thanks
 
Hi Jake
Is no that the keyDown event is not fired . Actually it is fired but you
can only notice it if that key was anything but the enter key . if that key
was the enter key then the event of pressing the key is captured and
handled by the form , there form your textbox don't reciieve any events .
If you set a key as the accept key of your form then any enter key press
on your form is handled by the click event handler of that button . the
only way not to allow your form capture that enter key event is to remove
the accept key . That is if you want to use the enter key for another
function anywhere inside your form ( with the textbox in your case ) . hope
that clears the issue .

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top