This is a migrated thread and some comments may be shown as answers.

Problem with Mnemonics

2 Answers 102 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Pawel
Top achievements
Rank 1
Iron
Pawel asked on 13 Jun 2018, 08:40 AM

Hi everyone,

I created my own class:

  public partial class RadButton
  {
    public CustomButton()
    {
      InitializeComponent();
    }
  }

after this I woud like to us it in RadForm1:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
  {
    public c()
    {
      InitializeComponent();
      CustomButton button = new CustomButton();
      button.Text = "&customButton";
      button.Click += Button_Click;
      Controls.Add(button);
    }

    private void Button_Click(object sender, EventArgs e)
    {
      RadMessageBox.Show("Test");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      RadMessageBox.Show("It is works");
    }
  }

 

why when I'm using my custom class I cannot use shortcuts:
"c" but only alt + "c" and it works. When I'm using standard buttons it works.

How can I fix it?

Best regards,

Pawel

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Jun 2018, 10:25 AM
Hello, Pawel,  

The following help article demonstrates briefly how to use mnemonics with RadButton: https://docs.telerik.com/devtools/winforms/buttons/mnemonics

By default, in order to perform the Click event when processing a mnemonic it is checked whether the Alt key is pressed. You can customize this logic by overriding the ProcessMnemonic method:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
 
        CustomButton button = new CustomButton();
        button.Text = "&customButton";
        button.UseMnemonic = true;
        button.Click += Button_Click;
        Controls.Add(button);
    }
 
    private void Button_Click(object sender, EventArgs e)
    {
        RadMessageBox.Show("Test");
    }
}
 
public class CustomButton : RadButton
{
    protected override bool ProcessMnemonic(char charCode)
    {
        if (this.UseMnemonic && TelerikHelper.CanProcessMnemonic(this) &&
              
            Control.IsMnemonic(charCode, this.Text))
        {
            this.PerformClick();
            return true;
        }
        return false;
    }
}

Now, the mnemonic will be processed without the necessity to press the Alt key.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Pawel
Top achievements
Rank 1
Iron
answered on 13 Jun 2018, 11:14 AM

Thank you a lot. It works for me now.

Best regards,

Pawel

Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Pawel
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Pawel
Top achievements
Rank 1
Iron
Share this question
or