One way you can suppress the KeyUp event (and the KeyDown event) is to
override the ProcessKeyMessage method and return true for the cases
you want to suppress. Here is code that 'eats' a's.
public class MyTextBox : TextBox
{
protected override bool ProcessKeyMessage(ref Message m)
{
Keys keyCode = (Keys)((int)m.WParam) & Keys.KeyCode;
if (keyCode == Keys.A || keyCode == (Keys.A + 32))
{
return true;
}
return base.ProcessKeyMessage(ref m);
}
}
====================
Clay Burch
Syncfusion, Inc.
robintw - 18 Jun 2007 10:01 GMT
Thanks for your response. I have tried your suggestion (I had to convert it
from C# to C++ - but I think I did that correctly) but I can't seem to quite
get it to work. I know that my overriden function is being called - as I have
a message box set to display at the beginning of the function - but no keys
seem to get through - even though I am only excluding F6 at the moment.
I notice your example was using a textbox - and I'm using it on a form. Is
that likely to cause any problems? I'm assuming it should still be possible!
The other thing I'm having a slight problem with is the last line -
base.ProcessKeyMessage. In Visual C++ .Net it does not seem to be possible to
access the base class by using the keyword 'base'. From what I've read I have
to fully specify the function I want to call. I've done this by changing the
last line to return System::Windows::Forms::Form::ProcessKeyMessage(m). Is
that likely to be correct? One possible reason for my problems could be that
that function is always returning true (because I've got the wrong function
or something) and therefore everything is being 'eaten'.
Thanks a lot for your help,
Robin
> One way you can suppress the KeyUp event (and the KeyDown event) is to
> override the ProcessKeyMessage method and return true for the cases
[quoted text clipped - 16 lines]
> Clay Burch
> Syncfusion, Inc.