How to send TAB keypress programmatically to netcf

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

I found many problems related to this in the app. Is there a way I can send the tab key to the form / edit field.

(Note that this must be in the Compact Framework.)


Solution:
Here's 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 give the answer to Hans because his code made me move towards the right solution.

+2


a source to share


1 answer


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

      

+2


a source







All Articles