Problem with Mnemonics

3 posts, 1 answers
  1. Pawel
    Pawel avatar
    4 posts
    Member since:
    Nov 2017

    Posted 13 Jun 2018 Link to this post

    Hi everyone,

    I created my own class:

      public partial class CustomButton : 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. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3469 posts

    Posted 13 Jun 2018 Link to this post

    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.
  3. Pawel
    Pawel avatar
    4 posts
    Member since:
    Nov 2017

    Posted 13 Jun 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you a lot. It works for me now.

    Best regards,

    Pawel

Back to Top