views:

35

answers:

1

I have a Windows Mobile application in C#.
I have a couple of fields on the form, and when I hit enter I want the form submitted.

Is there a way to mark a pushbutton as default?
Also how can I make so the Down key moves the focus into the next field? Tab-order is not respected?

+1  A: 
  1. You can have a method that you link as the KeyDown event on all the controls from that form. In that you check if the KeyCode is Enter then you call the Submit method.

    private void control_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) Submit(); }

  2. Same thing, in the KeyDown method you handle the DownArrow key. Im not sure if you have the System.Windows.Forms.Control.SelectNextControl() method in the Compact Framework, but if you don't have it you can easily build something like that by yourself.

Ovi
how can I read the TabOrder of a control on CF?
Pentium10
button1.TabIndex; But why would you need to read that, just use the SelectNextControl method with its parameters.
Ovi
Thanks. I am wondering why they didn't included this in the default KeyDown event. Adding this into all controls is pain. Also when the orientation changed the DownArrow key is no longer working.
Pentium10
Maybe when the orientation changes, the LeftArrow becomes your DownArrow.
Ovi