1.先定义一个类,以调用API (注:要按顺序先设置好控件的TabIndex) private class Win32Helper //创建个类 { public const int KEYEVENTF_KEYUP = 0x0002; [DllImport("coredll.dll")] public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); } 2.在窗体的KeyDown事件中添加如下代码:(按上下方向键实现文本框的Tab功能) protected void Form_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Down) { Win32Helper.keybd_event((byte)Keys.Tab, 0, 0, 0); } if (e.KeyCode == Keys.Up) { Win32Helper.keybd_event((byte)Keys.ShiftKey, 0, 0, 0); Win32Helper.keybd_event((byte)Keys.Tab, 0, 0, 0); Win32Helper.keybd_event((byte)Keys.Tab, 0, Win32Helper.KEYEVENTF_KEYUP, 0); Win32Helper.keybd_event((byte)Keys.ShiftKey, 0, Win32Helper.KEYEVENTF_KEYUP, 0); } } |
wince 实现 上下键控制TAB
最新推荐文章于 2019-08-08 08:59:00 发布