Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#3.5

How to display or hide standard button cues.

5.00/5 (6 votes)
18 Nov 2010CPOL 19.9K  
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)