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 the 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.