3

Delphi TextRectGDIに類似したものはありますか?見てみましたDrawText, DrawTextExが、必要なものが見つかりませんでした。2つの色の部分に分割されたプログレスバーのパーセントテキストを描画する必要があります。たとえば、テキストの左側は黒、右側は白です。したがって、通常のようにすべてのプログレスバーにあります。

ここに画像の説明を入力してください

あなたの答えをありがとう!

4

1 に答える 1

10

あなたはその機能を探していExtTextOutます。

サンプル:

procedure TForm4.FormPaint(Sender: TObject);
const
  S = 'This is a sample text';
begin
  ExtTextOut(Canvas.Handle, 10, 10, ETO_CLIPPED,
    Rect(40, 10, 100, 100), PChar(S), length(S), nil)    
end;

しかし、あなたが本当にやりたいのは、「色のないテキスト」を描くことだと思います。

procedure DrawTextNOT(const hDC: HDC; const Font: TFont; const Text: string; const X, Y: integer);
begin
  with TBitmap.Create do
    try
      Canvas.Font.Assign(Font);
      with Canvas.TextExtent(Text) do
        SetSize(cx, cy);
      Canvas.Brush.Color := clBlack;
      Canvas.FillRect(Rect(0, 0, Width, Height));
      Canvas.Font.Color := clWhite;
      Canvas.TextOut(0, 0, Text);
      BitBlt(hDC, X, Y, Width, Height, Canvas.Handle, 0, 0, SRCINVERT);
    finally
      Free;
    end;
end;

procedure TForm4.FormPaint(Sender: TObject);
const
  S = 'This is a sample text';
var
  ext: TSize;
begin
  Canvas.Brush.Color := clBlack;
  Canvas.FillRect(Rect(0, 0, Width div 2, Height));
  Canvas.Brush.Color := clWhite;
  Canvas.FillRect(Rect(Width div 2, 0, Width, Height));
  ext := Canvas.TextExtent(S);

  DrawTextNOT(Canvas.Handle, Canvas.Font, S, (Width - ext.cx) div 2,
    (Height - ext.cy) div 2);
end;

スクリーンショット
(出典:rejbrand.se

于 2011-08-28T17:26:07.000 に答える