Hello,
Thank you so much for bringing this thread back to me, which I completely forgot about...
The solution to my problem is to add a procedure (remember : "stb" is the name of my StatusBar) :
procedure TForm1.stbDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
var
w, h, x, y: Integer;
r: TRect;
begin
r.Create(Rect);
if StatusBar.SizeGrip and (Panel.Index = StatusBar.Panels.Count - 1) then
r.Width := r.Width - GetSystemMetrics(SM_CXVSCROLL) - GetSystemMetrics(SM_CXBORDER);
StatusBar.Canvas.Brush.Color := Form1.Color;
StatusBar.Canvas.Font := StatusBar.Font;
case (Panel.Index mod 3) of
0: StatusBar.Canvas.Font.Color := clBlue;
1: StatusBar.Canvas.Font.Color := clGreen;
2: StatusBar.Canvas.Font.Color := clRed;
end;
StatusBar.Canvas.FillRect(r);
w := StatusBar.Canvas.TextWidth(Panel.Text);
case Panel.Alignment of
taLeftJustify : x := r.Left + 2;
taRightJustify: x := r.Right - 2 - w;
taCenter: x := r.Left + (r.Width - w) div 2;
end;
h := StatusBar.Canvas.TextHeight(Panel.Text);
y := r.Top + (r.Height - h) div 2;
StatusBar.Canvas.TextOut(x, y, Panel.Text);
end;
and modify the FormCreate procedure as follows:
procedure TForm1.FormCreate(Sender: TObject);
var
aSimpleText: string;
begin
aSimpleText := 'A Simple Text';
stb.AutoSize := False;
stb.Height := 32;
stb.Font.Name := 'Aria Script SSi';
stb.Font.Size := 16;
stb.SimplePanel:=False; // needs that, even if only one panel
{//using that causes the Panels[0] to be badly aligned and with a wrong color
with stb.Panels.Add do begin
Style := psOwnerDraw;
Width := Form1.Width;
// a try Alignment := taLeftJustify;
Text := aSimpleText;
end;
stb.Panels[0].Alignment := taLeftJustify; // still bad }
stb.Panels.Add;
stb.Panels[0].Style := psOwnerDraw;
stb.Panels[0].Width := Form1.Width;
stb.Panels[0].Alignment := taLeftJustify;
stb.Panels[0].Text := aSimpleText;
stb.OnDrawPanel := @stbDrawPanel;
end;
And it works !
img good_statusbar
But caution with the lines I've commented out : see img bad_statusbar.
Big thanks to
paweld for refreshing my memory
Have a nice day,