Article is about to remove focus rectangle or say cues from Button in window form application.
First let discuss what default focus rectangle. Please look at following image , in that image OK button has default focus so it display cues rectangle.
(FlatStyle == System)
When we want to set background image of button to make button attractive in that case this default rectangle create problem with look and feel.
(FlatStyle = Standard)
(FlatStyle = Flat)
In above two image need to set FlatApperance.BorderStyle =0. You can visualize that in all above case default focus rectangle make button look ugly with background image.
To remove this cues ( Default focus rectangle ) you need to set ShowFocusCues property of Button to false but this property does not directly available to Button. This property available in ButtonBase class with protected access specifier. In order to set this property to false we need to create class that inherits from Button or ButtonBase and set this property explicitly false.
class CustomButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
Now see that default focus rectangle is removed.
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 so CustomButton work with any case. ( Want to display focus rectangle or not).
Hope this solution is help you to create button without cues.
Your suggestion is always invited.