开发者

How to mark a pushbutton as a default for Enter key on form elements?

开发者 https://www.devze.com 2022-12-20 05:33 出处:网络
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.

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 nex开发者_开发问答t field? Tab-order is not respected?


  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消