Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove focus rectangle from a button control?

I need to remove a button focus rectangle, because it looks bad over the TBitBtn glyph after the buttons is clicked.

like image 363
Mitsos Thrash'til'death Avatar asked Mar 09 '13 22:03

Mitsos Thrash'til'death


People also ask

How do you remove button focus?

To remove focus around the button outline:none property is used. Outline property: Outline is an element property which draws a line around element but outside the border.

How do you turn off focus in CSS?

To remove or disable focus border of browser with CSS, we select the styles for the :focus pseudo-class. to set the outline style to none to remove the border of the element that's in focus.


2 Answers

You can create an Interposer class for TBitBtn and override SetButtonStyle preventing it's internal IsFocused variable to be set:

type
  TBitBtn = class(Buttons.TBitBtn)
  protected
    procedure SetButtonStyle(ADefault: Boolean); override;
  end;

...
implementation

procedure TBitBtn.SetButtonStyle(ADefault: Boolean);
begin
  inherited SetButtonStyle(False);
end;

This will result a TBitBtn with no focus rectangle. (Tested with D7 - with/without Theme support).

like image 72
kobik Avatar answered Sep 21 '22 01:09

kobik


As a workaround, you can use a TSpeedButton, which does not take the focus and, consequently, never receives a focus rectangle.

like image 30
BeniBela Avatar answered Sep 20 '22 01:09

BeniBela