Mirror

How to write bold text on a TStatusBar (Views: 703)


Problem/Question/Abstract:

I need to write in bold or underlined in a statusbar. I have tried to use the owner draw options however I never get it right.

Answer:

Set the style property of the StatusPanel to psOwnerDraw and add following event handler:

procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
var
  ts: TSize;
begin
  with StatusBar.Canvas do
  begin
    Font.Style := [fsBold];
    ts := TextExtent(Panel.Text);
    TextRect(Rect, 0, (Rect.Top + Rect.Bottom - ts.cy) div 2, Panel.Text);
  end;
end;

<< Back to main page