【问题标题】:Center text in StringGrid in delphi [duplicate]delphi中StringGrid中的文本居中[重复]
【发布时间】:2016-10-04 04:44:28
【问题描述】:

我想知道如何在 StringGrid 中的单元格中心设置文本(垂直和水平)...我正在使用 StringGrid 的画布。

我正在使用 Delphi,我想要最简单的方法...

谁能帮帮我?

【问题讨论】:

    标签: delphi text alignment center stringgrid


    【解决方案1】:

    您可以使用具有一些格式化功能的 API 函数DrawText

    简单示例:

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      Grid: TStringGrid;
    begin
      Grid := Sender as TStringGrid;
      Grid.Canvas.FillRect(Rect);
      DrawText(Grid.Canvas.Handle, Grid.Cells[ACol, ARow],
               Length(Grid.Cells[ACol, ARow]),
               Rect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
    end;
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 2021-10-27
      相关资源
      最近更新 更多