Windows Develop Bookmark and Share   
 index > Windows Forms General > Label Mnemonic Custom Handling
 

Label Mnemonic Custom Handling

Hi,

I have a custom control derived from the Label class with a few extra features. I am having trouble implementing one of these:

Currently, as I'm sure you are aware, when ALT + the Mnemonic character of a Label control is pressed, the control with the next highest TabIndex property is given focus.

I wish write custom code to handle the this ALT + Mnemonic character keypress myself, without diverting focus to the next control at all.

I have tried overriding the OnEnter/OnGotFocus methods, but with no success.

I know it is possible because the LinkLabel class (which inherits from Label also) does it somehow!

Any other ideas?

Thanks.

Phizz  Friday, July 15, 2005 4:24 PM
After much pain and suffering, I have finally figured this one out. It's so simple I can't believe I didn't find it right away:


protected override bool ProcessMnemonic(char charCode)
{
   if (Control.IsMnemonic(charCode, Text))
   {
      /*custom handling here*/
      return true;
   }
   else
   {
      return false;
   }
}

 


Thanks anyway!
Phizz  Friday, July 15, 2005 8:07 PM
After much pain and suffering, I have finally figured this one out. It's so simple I can't believe I didn't find it right away:


protected override bool ProcessMnemonic(char charCode)
{
   if (Control.IsMnemonic(charCode, Text))
   {
      /*custom handling here*/
      return true;
   }
   else
   {
      return false;
   }
}

 


Thanks anyway!
Phizz  Friday, July 15, 2005 8:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Problem with Object-binding to a combobox in Winforms. (Possible Framework error?)
• Basic question about using custom files/classes
• ListView in c#
• Error creating window handle
• How to show a picture from sql server( BLOB type )
• copy txt file to compile location
• Beginner Needs Help: How to make a window that takes UART data
• A date Question
• Text truncates in Icon view of a Listview control
• The value of DataGridViewRow.Tag is lost after sorting