开发者

How to programatically send a TAB keystroke in netcf

I need to have my edit box work the same for both tab and the enter key.

I have found lots of problems doing this in the application. Is there some way that I can send a tab key to t开发者_如何学JAVAhe form/edit box.

(Note that this has to be in the Compact Framework.)


Solution:

Here is what I ended up using:

// This class allows us to send a tab key when the the enter key is pressed for the mooseworks mask control.   
public class MaskKeyControl : MaskedEdit
{
    [DllImport("coredll.dll", EntryPoint = "keybd_event", SetLastError = true)]
    internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    public const Int32 VK_TAB = 0x09;

    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            keybd_event(VK_TAB, VK_TAB, 0, 0);
            return;
        }
        base.OnKeyDown(e);
    }

    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        if (e.KeyChar == '\r') 
            e.Handled = true;
        base.OnKeyPress(e);
    }
}

I am giving the answer to Hans because his code got me moving toward the right solution.


You could try this control:

using System;
using System.Windows.Forms;

class MyTextBox : TextBox {
    protected override void OnKeyDown(KeyEventArgs e) {
        if (e.KeyData == Keys.Enter) {
            (this.Parent as ContainerControl).SelectNextControl(this, true, true, true, true);
            return;
        }
        base.OnKeyDown(e);
    }
    protected override void OnKeyPress(KeyPressEventArgs e) {
        if (e.KeyChar == '\r') e.Handled = true;
        base.OnKeyPress(e);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜