How to autosize TsStatusBar panels

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35879
    Gabor Boros
    Participant

    Hi,

    I want to autosize panels on statusbar independent from the displayed text. Worked out a solution which perfect with Windows XP but not with Windows 7.

    Any OS independent solution is available? See the attached files.

    Gabor

    #50957
    Support
    Keymaster

    Hi

    I will check it soon.

    #50969
    BuzzLeclaire
    Participant

    Hello,

    Maybe using this function

    Code:
    Function TextSize(Phrase : string; Police : TFont = nil) : TPoint;
    var
    DC: HDC;
    Rect: TRect;
    C : TBitmap;
    begin
    C := TBitmap.create;
    if police <> nil then C.canvas.Font := police;

    Rect.Left := 0;
    Rect.Top:=0;
    Rect.Right:=0;
    Rect.Bottom:=0;
    DC := GetDC(0);
    C.Canvas.Handle := DC;
    DrawText(C.Canvas.Handle, PChar(Phrase), Length(Phrase), Rect, (DT_EXPANDTABS or DT_CALCRECT));
    C.Canvas.Handle := 0;
    ReleaseDC(0, DC);
    result.X:=Rect.Right-Rect.Left;
    result.Y:=Rect.Bottom-Rect.Top;
    C.Free;
    end;

    This function returns the width and height of the text.

    Bye.

    #50990
    Support
    Keymaster
    'Gabor wrote:
    Hi,

    I want to autosize panels on statusbar independent from the displayed text. Worked out a solution which perfect with Windows XP but not with Windows 7.

    Any OS independent solution is available? See the attached files.

    Gabor

    Hello! Your code is correct, just add this line before width calculation:

    in_StatusBar.Canvas.Font.Assign(in_StatusBar.Font);

    #51012
    Gabor Boros
    Participant
    'Support' wrote:

    Hello! Your code is correct, just add this line before width calculation:

    in_StatusBar.Canvas.Font.Assign(in_StatusBar.Font);

    Hi,

    Works like a charm! :a7: Thank You!

    Gabor

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.