Search code examples
c#.netwinformscontrolsmnemonics

How to Add shortcut key to checkbox without text


I want to add shortcut key to checkbox. Checkbox do not have text. I have label and then Checkbox. Label have shortcut key for ex. &Visible. So, Label have V as shortcut key. If someone press Alt+V then chechbox should change from selected to not selected state and same in opposite manner.


Solution

  • You can check it like this refer the following code part.

            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                // look for the expected key 
                if (keyData == Keys.Alt && keyData == Keys.V)
                {
                    checkBox1.Checked = true;
                    return true;
                }
                else
                {
                    checkBox1.Checked = false;
                    return false;
                }
            }