Click here to Skip to main content
15,880,796 members
Articles / Programming Languages / C# 3.5
Tip/Trick

How to display or hide standard button cues.

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
18 Nov 2010CPOL 19.4K   3   1
When we set focus on a standard button by pressing Tab key on the
keyboard or clicking mouse button on it, it displays a cue (a rectangle
with dotted lines). Sometimes it is needed for the cue to not appear
e.g. buttons with vista or windows 7 glossy looks. The cue over such
buttons makes it look too old or win95-ish.
To remove the cue you need to set the ShowFocusCues property of the
button to False. But this property is not directly available to the
programmer. This property is available in the ButtonBase class with
protected access specifier. In order to set this property to false we
need to create a class that inherits from ButtonBase and set this
property explicitly to False.

class CustomButton : System.Windows.Forms.Button
{
   protected override bool ShowFocusCues
   {
      get
      {
         return false;
      }
   }
}


More generic class for Button.

class CustomButton : System.Windows.Forms.Button
   {
       private bool _DisplayFocusCues = true;
       protected override bool ShowFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
       }
       public bool DisplayFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
           set
           {
               _DisplayFocusCues = value;
           }
       }
   }

Using this class you can set DisplayFocusCues at design time too.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThank you Pin
N. Henrik Lauridsen20-Apr-15 9:01
N. Henrik Lauridsen20-Apr-15 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.