Supress KeyDown event in custom class

D

David

I have a custom control that contains a class that Inherits the panel
control. I am trying to catch a keydown event in this class and then
supress it from the rest of the control as well as the form that hosts
the control. The problem I am running into is that the form that hosts
the control will respond to the keydown event event.

Any ideas what I am missing?

Some source code to help:

public class PanelEditor : Panel {

... boring code omitted....

protected override void OnKeyDown(KeyEventArgs e) {
this.m_Text += (Keys)e.KeyValue;
this.m_CharCount++;

e.Handled =true;
base.OnKeyDown (e);
}
}

Again, this derived panel is part of a C# Windows Control Library.

-David
 
G

Guest

Ok, I have it fixed. Here is the code that would replace the OnKeyDown override and supress the key

public override bool PreProcessMessage(ref Message msg)
switch(msg.Msg)
case 0x0100: //WM_KEYDOW

... Do your key stuff here ..

msg.WParam = IntPtr.Zero; //Set this to zero to supress the key strok
break


return base.PreProcessMessage (ref msg)
}
 
G

Guest

Hi David,

Is your problem really resolved?

I have tried your code, it does not suppress the key press for its child
controls.(At least, it can not suppress key stroke in textbox child control)

After do some research, I have find a worked solution for you, like this:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(msg.Msg==0x0100)
{
if(keyData==Keys.Delete)
{
return true;
}
}
return base.ProcessCmdKey (ref msg, keyData);
}

In the code, I suppress the "delete" key stroke in its child controls.

Please apply my suggestion to see if it resolved your problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi David,

Does my reply make sense to you? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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