RadLabel Always Capture Key Events

3 posts, 0 answers
  1. Vinicius
    Vinicius avatar
    9 posts
    Member since:
    Dec 2011

    Posted 09 Jul 2012 Link to this post

    Hi,
    I have an application using RadControls for WinForms C# (v.2012.1.321.20) and I got some issues with RadLabels. There's a RadPanel capturing Key-Up Events and 2 RadLabels above the panel just to show some information about the key pressed (labels dont capture any event, just the panel all the time), and it works fine except for the 4 navigation keys: Up,Down,Left and Right. When one of those keys is pressed the panel miss it twice, and just on the third time the panel get the event. It looks like the navigation key is changing the focus between these 2 labels and the panel, and I tried a lot of things to avoid this like:

    - Set label's "Focusable" property to false;
    - Create an "Preview KeyDown" event that set focus on RadPanel before the KeyUp event is handled;

    Nothing fixed it out and radlebels still getting Key-Up events instead of RadPanel, so I would like to know if there's any solution for this issue (because it's not happening with others controls above the panel like Microsoft Label Control).

    Thanks!
  2. Vinicius
    Vinicius avatar
    9 posts
    Member since:
    Dec 2011

    Posted 09 Jul 2012 Link to this post

    One more information: I tried to disable the RadLabels (Enable=false) and it worked fine, but I can't change the font color or appareance in disabled control. If i would change the font color of disabled label (looking like enabled) it would be fine in my application.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 12 Jul 2012 Link to this post

    Hi Vinicius,

    Thank you for writing.

    In order to be able to catch the KeyUp of event of a key, it should be InputKey. Arrow keys by default are considered as system keys, thus you are not able to catch their KeyUp event. To allow that, you need to create a descendant of RadPanel, override its IsInputKey method and return true if arrow key is pressed. In the example below, I am returning true in all cases in order to get the KeyUp event for every possible key:
    class MyPanel : RadPanel
    {
        protected override bool IsInputKey(Keys keyData)
        {
            return true;
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadPanel).FullName;
            }
        }
    }

    I hope this helps.
     
    All the best,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top