c# - 如何以编程方式在 netcf 中发送 TAB 击键

标签 c# .net compact-framework

我需要让我的编辑框对 Tab 键和回车键的工作方式相同。

我在应用程序中发现了很多问题。有什么方法可以将 Tab 键发送到表单/编辑框。

(请注意,这必须在 Compact Framework 中。)


解决方案:
这是我最终使用的:

// 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);
    }
}

我将答案交给 Hans,因为他的代码让我朝着正确的解决方案前进。

最佳答案

你可以试试这个控件:

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);
    }
}

关于c# - 如何以编程方式在 netcf 中发送 TAB 击键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2829333/

相关文章:

windows-mobile - 防止 Pocket-PC 进入横向模式

c# - 是否有模拟 facebook 的 "Link Detect"的库?

c# - Blazor 将数据从父级传递给子级

c# - 适用于 Windows Mobile 的 gzip 工具比 SharpZipLib 更好?

c# - 从命令行打印 xhtml?

.net - 如何将发送到我的 azure 网站的电子邮件重定向到另一个域上的客户电子邮件

c# - HttpRequest/HttpResponse内存泄漏? CF.NET 3.5 WIN CE 6.0

c# - 自定义msiexec进度条?

c# - Breeze 过滤。在服务器端展开

c# - 不区分大小写的字符串搜索