Suppress key strokes in UserControl, ProcessKeyPreview

  • Thread starter Thread starter Marius Horak
  • Start date Start date
M

Marius Horak

ProcessKeyPreview in a UserControl works fine to intercept most of the
keys. But I would like to suppress some keys.

private Keys keyMultiply = Keys.Multiply;

.....
.....

protected override bool ProcessKeyPreview(ref
System.Windows.Forms.Message msg)
{
if (msg.Msg == WM_KEYDOWN)
{
if ((Int32)msg.WParam == (Int32)_keyPrintOrder)
{
MessageBox.Show("*");
return true;
}
}
return base.ProcessKeyPreview(ref msg);
}

When the active control is for example a textbox * will get to it
before MessageBox.Show is being shown. How come? How to suppress keys
in UserControl?


Thanks

MH
 
try handle the KeyDown event.

private void test_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Multiply)
e.Handled=true;
}

Calle
:-)
 
Back
Top