Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#5

Re: [Statusbar] Breite eines Panels

  Alt 21. Mär 2008, 06:40
Angelehnt an die Funktion von shima könnte die AutoResize Funktion so aussehen.
(verwendet anstatt die von shima verwendete TrueFontWidth Funktion Canvas.Font := Font)

Delphi-Quellcode:
uses
  CommCtrl;

procedure AutoSizeStatusbarPanels(sb: TStatusbar);
var
  iPanel: Word;
  borders : array[0..2] of Integer;
begin
  With sb do
  begin
    // Don't deal with simple panels
    if SimplePanel then Exit;
    // Assign the Font to Canvas.Font
    Canvas.Font := Font;
    // get the Borders of the Statusbar
    // border[2] = Width of the Border between Rectangles
    SendMessage(Handle, SB_GETBORDERS, 0, Integer(@borders));
    for iPanel := 0 to Panels.Count -2 do // Don't resize the last panel
    begin
     // Calculate the Width of the Panel
      Panels.Items[iPanel].Width := Canvas.TextWidth(Panels.Items[iPanel].Text) +
      borders[2] * 2 + 3; // Vertical Border * 2 + 3 extra Pixels
    end;
  end;
end;
Thomas
  Mit Zitat antworten Zitat