Prevent Focus

4 posts, 0 answers
  1. Hesham Desouky
    Hesham Desouky avatar
    28 posts
    Member since:
    Oct 2012

    Posted 19 Mar 2012 Link to this post

    Is it possible to prevent the CommandBar getting focus from current focused control
  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 21 Mar 2012 Link to this post

    Hello Hesham, 

    Thank you for writing.

    If you would like prevent RadCommandBar from taking the focus, you can use set its TabStop property to false. In this way when the user presses Tab the control will be skipped.

    In case I have misunderstood your requirement, I kindly ask you to provide more details on your scenario. A detailed explanation, code snippets, or screenshots are possible ways of conveying important information regarding your scenario. Once I am able to fully understand your case, I will do my best to provide you with solution.

    Kind regards,
    Boryana
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hesham Desouky
    Hesham Desouky avatar
    28 posts
    Member since:
    Oct 2012

    Posted 22 Mar 2012 Link to this post

    Hello Boryana,
    Thanks for your prompt reply.

    The scenario is when having certain control in the the form with focus, the focus is lost when clicking one of the RadCommandBar button. This is not related to tabstop but to the mouse clicks.
    This is not true for RadMenu, RadMenu didn't receive focus when selecting one of the menu items while RadCommandBar elements receive focus when clicking any of the bar elements.

    This causes user to lose the ability to e.g. scrolling the focused control using mouse scroll wheel before clicking the RadCommandBar button after performing the click

    Which requires the user to click the required control again to be able to scroll.

    I tried a technique to return focus to desired control after clicking RadCommandBar item, but I think this solution is not good because the unfocusing/focusing cues give the user odd experience

    What you think
  5. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 26 Mar 2012 Link to this post

    Hello,

    Thank you for clarifying your scenario. 

    You can easily avoid the default behavior of RadCommandBar through overriding the ProcessFocusRequested method. Create a class that derives from RadCommandBar and set its ThemeClassName property, so that the theming mechanism can theme it as a RadCommandBar. Further, override the ProcessFocusRequested method and make it always return false:
    class MyCommandBar: RadCommandBar
    {
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadCommandBar).FullName;
            }
        }
     
        protected override bool ProcessFocusRequested(RadElement element)
        {
            return false;
        }
    }

    The attached sample project demonstrates the above approach.

    I hope this helps. Let me know if you have further questions.

    Regards,
    Boryana
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top