Mirror

Justify the caption of a TForm (Views: 100)


Problem/Question/Abstract:

I'd like to insert enough spaces between two strings to make a caption for a titlebar show the pieces justified left and right. For example, program name on the left and copyright notice on the right.

Answer:

The DrawText API function supports drawing justified text. Below is an example:

{ ... }
var
  R: TRect;
  fmt: UINT;
begin
  R := ClientRect; {define your rectangle to draw the text}
  with Canvas do {canvas to paint on}
  begin
    fmt := DT_LEFT;
    DrawText(Handle, PChar(LeftSide), Length(LeftSide), R, fmt);
    fmt := DT_RIGHT;
    DrawText(Handle, PChar(RightSide), Length(RightSide), R, fmt);
  end;
end;

<< Back to main page