I have a windows form, i need when user press Enter set focus to next control. Any idea how to achive this (without using Key Press events)
You can catch the KeyPreview of your form. Set KeyPreview to true in the constructor and then you can use this:
protected override bool ProcessKeyPreview(ref Message m)
{
if (m.Msg == 0x0100 && (int)m.WParam == 13)
{
this.ProcessTabKey(true);
}
return base.ProcessKeyPreview(ref m);
}
You can use ProcessCmdKey checking if keyData contains the Enter Key then using the SelectNextControl
Method to set your focus.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData.HasFlag(Keys.Enter))
{
SelectNextControl(ActiveControl,true,true,true,true);
return true; //Stops the beeping
}
return base.ProcessCmdKey(ref msg, keyData);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With