Suppress key strokes in UserControl, ProcessKeyPreview

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
 
C

carl.henrik.bache

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
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top