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

Shortcuts problem inconsistent behaviour

7 Answers 422 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Reggie Pangilinan
Top achievements
Rank 1
Reggie Pangilinan asked on 07 Apr 2010, 06:37 PM
Hello guys,

I am having a problem with the shortcut control. I want to assign a shortcut key for a radbutton within a radform
so i added a radbutton and a shortcut control in the radform. 

In the shortcut control i add input bindings for the radbutton
-  Chord       == CTRL+N
-  Command == ActionCommand
-  Context     == radbutton1

so its suppose to fire the click event for the radbutton. but sadly im not getting any response.

So i tried another control which is the radtextbox doing all the same procedure as i did for the radbutton. the only difference is the
input binding command == FocusCommand. Surprisingly when i press the shortcut for focus which is (CTRL+F) the textbox was focused successfully?

Am i missing something? What are the possible solutions/workaround for this problem. i attached the source code.

BTW i am using Winforms Q3 2009


Here is my source code

    public partial class SPRadButton : Telerik.WinControls.UI.RadForm 
    { 
        public SPRadButton() 
        { 
            InitializeComponent(); 
        } 
 
        private void radButton1_Click(object sender, EventArgs e) 
        { 
            RadMessageBox.Show("success"); 
        } 
    } 


    partial class SPRadButton 
    { 
        /// <summary> 
        /// Required designer variable. 
        /// </summary> 
        private System.ComponentModel.IContainer components = null
 
        /// <summary> 
        /// Clean up any resources being used. 
        /// </summary> 
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
        protected override void Dispose(bool disposing) 
        { 
            if (disposing && (components != null)) 
            { 
                components.Dispose(); 
            } 
            base.Dispose(disposing); 
        } 
 
        #region Windows Form Designer generated code 
 
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor. 
        /// </summary> 
        private void InitializeComponent() 
        { 
            this.components = new System.ComponentModel.Container(); 
            Telerik.WinControls.Keyboard.InputBinding inputBinding1 = new Telerik.WinControls.Keyboard.InputBinding(); 
            Telerik.WinControls.Keyboard.Chord chord1 = new Telerik.WinControls.Keyboard.Chord(); 
            Telerik.WinControls.Keyboard.ChordModifier chordModifier1 = new Telerik.WinControls.Keyboard.ChordModifier(); 
            Telerik.WinControls.Elements.ClickCommand clickCommand1 = new Telerik.WinControls.Elements.ClickCommand(); 
            Telerik.WinControls.Keyboard.InputBinding inputBinding2 = new Telerik.WinControls.Keyboard.InputBinding(); 
            Telerik.WinControls.Keyboard.Chord chord2 = new Telerik.WinControls.Keyboard.Chord(); 
            Telerik.WinControls.Keyboard.ChordModifier chordModifier2 = new Telerik.WinControls.Keyboard.ChordModifier(); 
            Telerik.WinControls.Elements.FocusCommand focusCommand1 = new Telerik.WinControls.Elements.FocusCommand(); 
            Telerik.WinControls.Keyboard.InputBinding inputBinding3 = new Telerik.WinControls.Keyboard.InputBinding(); 
            Telerik.WinControls.Keyboard.Chord chord3 = new Telerik.WinControls.Keyboard.Chord(); 
            Telerik.WinControls.Keyboard.ChordModifier chordModifier3 = new Telerik.WinControls.Keyboard.ChordModifier(); 
            Telerik.WinControls.Elements.ClickCommand clickCommand2 = new Telerik.WinControls.Elements.ClickCommand(); 
            this.radButton1 = new Telerik.WinControls.UI.RadButton(); 
            this.radTextBox1 = new Telerik.WinControls.UI.RadTextBox(); 
            this.shortcuts1 = new Telerik.WinControls.Keyboard.Shortcuts(this.components); 
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit(); 
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).BeginInit(); 
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); 
            this.SuspendLayout(); 
            //  
            // radButton1 
            //  
            chordModifier1.AltModifier = false
            chordModifier1.ControlModifier = true
            chordModifier1.ShiftModifier = false
            chord1.ChordModifier = chordModifier1
            chord1.Keys = "Ctrl+N"
            inputBinding1.Chord = chord1
            clickCommand1.ContextType = null
            clickCommand1.ImageList = null
            clickCommand1.Name = "ActionCommand"
            clickCommand1.OwnerType = typeof(Telerik.WinControls.RadItem); 
            clickCommand1.Text = "This command rises the Click event of a selected RadItem instance."
            clickCommand1.Type = ""
            inputBinding1.Command = clickCommand1
            inputBinding1.CommandContext = this.radButton1; 
            this.radButton1.CommandBindings.AddRange(new Telerik.WinControls.Keyboard.InputBinding[] { 
            inputBinding1}); 
            this.radButton1.Location = new System.Drawing.Point(30, 23); 
            this.radButton1.Name = "radButton1"
            this.radButton1.Size = new System.Drawing.Size(237, 23); 
            this.radButton1.TabIndex = 0
            this.radButton1.Text = "CTRL+N"
            this.radButton1.Click += new System.EventHandler(this.radButton1_Click); 
            //  
            // radTextBox1 
            //  
            this.radTextBox1.Location = new System.Drawing.Point(30, 52); 
            this.radTextBox1.Name = "radTextBox1"
            this.radTextBox1.NullText = "Press CTRL+F to focus"
            this.radTextBox1.Size = new System.Drawing.Size(237, 20); 
            this.radTextBox1.TabIndex = 1; 
            //  
            // shortcuts1 
            //  
            chordModifier2.AltModifier = false
            chordModifier2.ControlModifier = true
            chordModifier2.ShiftModifier = false
            chord2.ChordModifier = chordModifier2
            chord2.Keys = "Ctrl+F"
            inputBinding2.Chord = chord2
            focusCommand1.ContextType = null
            focusCommand1.ImageList = null
            focusCommand1.Name = "FocusCommand"
            focusCommand1.OwnerType = typeof(Telerik.WinControls.RadItem); 
            focusCommand1.Text = "This command gives the focus to a selected RadItem instance."
            focusCommand1.Type = ""
            inputBinding2.Command = focusCommand1
            inputBinding2.CommandContext = this.radTextBox1; 
            chordModifier3.AltModifier = false
            chordModifier3.ControlModifier = true
            chordModifier3.ShiftModifier = false
            chord3.ChordModifier = chordModifier3
            chord3.Keys = "Ctrl+N"
            inputBinding3.Chord = chord3
            clickCommand2.ContextType = null
            clickCommand2.ImageList = null
            clickCommand2.Name = "ActionCommand"
            clickCommand2.OwnerType = typeof(Telerik.WinControls.RadItem); 
            clickCommand2.Text = "This command rises the Click event of a selected RadItem instance."
            clickCommand2.Type = ""
            inputBinding3.Command = clickCommand2
            inputBinding3.CommandContext = this.radButton1; 
            this.shortcuts1.InputBindings.AddRange(new Telerik.WinControls.Keyboard.InputBinding[] { 
            inputBinding2, 
            inputBinding3}); 
            thisthis.shortcuts1.Owner = this; 
            //  
            // SPRadButton 
            //  
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
            this.ClientSize = new System.Drawing.Size(293, 88); 
            this.Controls.Add(this.radTextBox1); 
            this.Controls.Add(this.radButton1); 
            this.Name = "SPRadButton"
            //  
            //  
            //  
            this.RootElement.ApplyShapeToControl = true
            this.Text = "RadForm1"
            this.ThemeName = "ControlDefault"
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit(); 
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).EndInit(); 
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); 
            this.ResumeLayout(false); 
            this.PerformLayout(); 
 
        } 
 
        #endregion 
 
        private Telerik.WinControls.UI.RadButton radButton1; 
        private Telerik.WinControls.Keyboard.Shortcuts shortcuts1; 
        private Telerik.WinControls.UI.RadTextBox radTextBox1; 
    } 



Thanks in advance

7 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 13 Apr 2010, 09:23 AM
Hello Reggie,

Thank you for contacting us and for reporting this issue.

There are certain issues with the Shortcuts/Chords support which we began addressing as of Q1 2010 SP1. We decided to entirely revise this logic and provide a new implementation using cleaner and simpler concepts since the old implementation had its limitations and also did not work as expected. In Q1 2010 SP1 you can use this new implementation, however, we still do not have a design time support for it. You can add shortcuts only programmatically:

RadShortcut shortCut = new RadShortcut(Keys.Control, Keys.B); this.radButton1.ButtonElement.Shortcuts.Add(shortCut);

As you can see, the code needed to add a shortcut to your button is shorter and much more clear.

You can download our latest Q1 2010 SP1 release and give it a try.

I hope this helps.

All the best,
Deyan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Reggie Pangilinan
Top achievements
Rank 1
answered on 13 Apr 2010, 04:15 PM
That means i have to purchase that latest release? Why cant it be included in Q3 2009 sp2 maybe? 
0
Vassil Petev
Telerik team
answered on 14 Apr 2010, 09:10 AM
Hello Reggie Pangilinan,

Just like all software, our evolves as well. We have to stay in business by constantly improving our products, so that our customers see value in using our tools. We fix bugs all the time, but they are fixed in our latest branch only and we do not include them in preceding versions. The reason is simple - almost all of our clients own subscription licenses and have access to the latest and greatest version of our tools. Still, we value our customer's needs, and if we get more requests to include this patch in the Q2 2009 version, we will try to provide a patch for Q3.

To our regret, there is no workaround we can suggest for Q3.


Best wishes,
Vassil
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Arul S V
Top achievements
Rank 1
answered on 21 Apr 2010, 12:06 PM
Hi,

    I've some problem with Accesskey [Shortcut key (ALT+A)] setting in winform RADBUTTON.

    Actaully i've a button with the Text "Add" and letter "A" is my shortcut key.
i made it by setting the text property of the radbutton to "&Add".

my problem is, If i press "A" in the form without pressing ALT key, my add radbutton click is getting triggered.
I want radbutton click event should be triggered only when i press ALT+A. if i press A alone then radbutton click event should not get triggered. i tried using shortcut control but i failed.

give me solutions for the above problem as soon as possible i'm in critical situations. at the same time can i use shortcut control with radbutton control if yes then send me the sample code or links. 
i'm using RAD Q3 2009 version & visual studio 2008

Thanks & Regards,
Arul
0
Nikolay
Telerik team
answered on 26 Apr 2010, 04:28 PM
Hi Arul,

In your case you are using mnemonics (&Add). However, please note that mnemonics do not need the Alt key to get triggered. What you really need for your case are shortcuts. Please consider the following code snippet (Q3 2009):
ChordModifier chordModifier1 = new ChordModifier();
chordModifier1.AltModifier = true;
chordModifier1.ControlModifier = false;
chordModifier1.ShiftModifier = false;
Chord chord1 = new Chord();
chord1.ChordModifier = chordModifier1;
chord1.Keys = "Alt+R";
InputBinding inputBinding1 = new InputBinding();
inputBinding1.Chord = chord1;
ClickCommand clickCommand1 = new ClickCommand();
clickCommand1.ContextType = null;
clickCommand1.ImageList = null;
clickCommand1.Name = "ActionCommand";
clickCommand1.OwnerType = typeof(Telerik.WinControls.RadItem);
clickCommand1.Text = "This command rises the Click event of a selected RadItem instance.";
clickCommand1.Type = "";
inputBinding1.Command = clickCommand1;
inputBinding1.CommandContext = this.radButton1.ButtonElement;
this.radButton1.CommandBindings.AddRange(new Telerik.WinControls.Keyboard.InputBinding[] {inputBinding1});

I hope that this information is helpful. If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Daniel Booth
Top achievements
Rank 2
answered on 20 Jun 2011, 06:59 PM

Rather than add a "shortcut", we just did this:

 

protected

 

override bool ProcessMnemonic(char charCode)

 

{

 

    if (CanSelect && IsMnemonic(charCode, Text) && (ModifierKeys == Keys.Alt))

 

 

        return base.ProcessMnemonic(charCode);

 

 

 

    return false;

 

}

Now we get the nice underlined character, but it only fires the click event if the ALT key is also pressed.

0
Nikolay
Telerik team
answered on 27 Jun 2011, 03:27 PM
Hi Daniel,

Thank you for sharing your solution with the community.

Indeed, depending on the exact scenario and controls used, you can use mnemonics in some cases. In other scenarios, however, RadShorcut is the best mechanism for applying key combinations on controls. My previous response concerns an old implementation of our shortcuts. You will be happy to know that we introduced a new version of our shortcuts in our latest releases. The new implementation has much cleaner API and works better. You can learn more about the new implementation here.

Regards,
Nikolay
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
General Discussions
Asked by
Reggie Pangilinan
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Reggie Pangilinan
Top achievements
Rank 1
Vassil Petev
Telerik team
Arul S V
Top achievements
Rank 1
Nikolay
Telerik team
Daniel Booth
Top achievements
Rank 2
Share this question
or