unit misc;
interface
uses Windows, Classes, Graphics;

procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer;
  const Text: string; Alignment: TAlignment);

implementation

procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer;
  const Text: string; Alignment: TAlignment);
const
  AlignFlags : array [TAlignment] of Integer =
    ( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
      DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
      DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX );
var
  Left: Integer;
begin
  case Alignment of
    taLeftJustify:
      Left := ARect.Left + DX;
    taRightJustify:
      Left := ARect.Right - ACanvas.TextWidth(Text) - 3;
  else { taCenter }
    Left := ARect.Left + (ARect.Right - ARect.Left) shr 1
      - (ACanvas.TextWidth(Text) shr 1);
  end;
  ACanvas.TextRect(ARect, Left, ARect.Top + DY, Text);
end;

end.
