Professional UI Solutions
Site Map   /  Register


Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Ribbon Tech Support » OnKeyPress and ONKeyDown events for mainform Collapse All
Subject Author Date
Helmut Wahrmann Jun 1, 2010 - 4:21 PM

I have the ribbon in a UserControl, which is placed on the Main Form.

in my Main Form i have:
"protected override void OnKeyPress(KeyPressEventArgs e)" and "protected override void OnKeyDown(KeyEventArgs e)" to capture various key strokes.

Seems the ribbon is consuming all keypress and keydown events. I’m not getting them in my form anymore.

Technical Support Jun 2, 2010 - 4:39 AM

We think that the problem isn’t related to the ribbon. The keyboard events are only passed to the control which currently has a focus. When you put different controls onto the form they can gain focus and receive keyboard strokes instead. Try using ProcessDialogKeyMethod like it is shown below:

protected override bool ProcessDialogKey(Keys keyData)
   KeyEventArgs e = new KeyEventArgs(keyData);
   Keys myKey = e.KeyCode;
   return base.ProcessDialogKey(keyData);

Helmut Wahrmann Jun 2, 2010 - 1:50 PM

Yeah, it was another control stealing focus.
However your suggested method didn’t solve my problem.

I found 2 other solutions, which both worked for me:

1. On the Mainform set the KeyPreview property to true, then the form will receive keys before any other

2. use "protected override bool ProcessCmdKey(ref Message msg, Keys keyData)" in stead of OnkeyDown and OnKeyPress overrides

thanks anyway for your support