Delphi 如何从TGridPanel';当它有大的边框宽度时,是s单元格吗?

Delphi 如何从TGridPanel';当它有大的边框宽度时,是s单元格吗?,delphi,graphics,draw,vcl,Delphi,Graphics,Draw,Vcl,我试图在覆盖绘制事件的TGridPanel中绘制每个单元格。我通过CellRect[Row,Col]获得每个单元格的Rect。在报告边缘之前,此操作一直有效。在这种情况下,即使是designtime中的设计也是错误的:单元格的“ClientRect”与CellRect的返回不对应 我试图调整从 CelcReuts获得的ReCT,但是考虑每个位移率是非常复杂的。在下图中,我有一个带有3px边框的TGripanel,每个面板的与边距对齐=true,所有边距=3px 有人经历过这种情况吗 天然涂料:

我试图在覆盖绘制事件的
TGridPanel
中绘制每个单元格。我通过
CellRect[Row,Col]
获得每个单元格的Rect。在报告边缘之前,此操作一直有效。在这种情况下,即使是designtime中的设计也是错误的:单元格的“ClientRect”与
CellRect
的返回不对应

<>我试图调整从<代码> CelcReuts获得的ReCT,但是考虑每个位移率是非常复杂的。在下图中,我有一个带有3px边框的TGripanel,每个面板的
与边距对齐
=true,所有
边距
=3px

有人经历过这种情况吗

天然涂料:
边框宽度
=3
BorderStyle
=bsNone (每个面板都是
align
=
alclient
AlignWithMargins
=
True

获取单元格“ClientRect”的代码:

procedure TMyCustomGridPanel.paint;
var
  Row, Col: Integer;
  rctCell: TRect;

  function GetColor(C, R: Integer): TColor;
  begin
    if odd(C + R) then
      Result:= clblack
    else
      Result:= clWhite;
  end;
begin
  inherited;

 for Row := 0 to RowCollection.Count -1 do
  begin
    for Col := 0 to ColumnCollection.Count -1 do
    begin
      Canvas.Brush.Color := GetColor(Col, Row);
      if Canvas.Brush.Color <> clDefault then
      begin
        rctCell := CellRect[Col, Row];

        {$REGION 'Adjust first col an row'}
        if Col = 0 then
          rctCell.SetLocation(rctCell.Location.X + BorderWidth, rctCell.Location.Y);

        if Row = 0 then
          rctCell.SetLocation(rctCell.Location.X, rctCell.Location.Y + BorderWidth);
        {$ENDREGION}

        {$REGION 'ajust last cells'}
        if Col = (ColumnCollection.Count -1) then
        begin
          if Col > 0 then // tem mais de uma coluna
            rctCell.SetLocation(rctCell.Location.X - BorderWidth, rctCell.Location.Y);
          rctCell.Right := ClientRect.Right;
        end;

        if Row = (RowCollection.Count -1) then
        begin
          if Row > 0 then
            rctCell.SetLocation(rctCell.Location.X, rctCell.Location.Y - BorderWidth);
          rctCell.Bottom := ClientRect.Bottom;
        end;

        {$ENDREGION}
        Canvas.Pen.Style := psClear;
        Canvas.FillRect(rctCell);
      end;
    end;
  end;

end;

单元格边框(虚线)的设计时渲染
TGridPanel
的属性不考虑面板的边界。因此,它们在视觉上与放置在网格单元中的组件不一致。这一点最为明显,例如
Align
属性设置为
alClient
的面板

要知道单元格的实际矩形,在
TGridPanel
的坐标中,可以使用
OffsetRect
调整边框宽度

var
  row, col: integer;
  r: TRect;
begin
  ...
  r := CellRect[Col, Row];
  OffsetRect(r, BorderWidth, BorderWidth);

不清楚您真正想要做的是什么。如果您想在面板中绘制某些内容,您应该覆盖面板中的
paint()
,而不是
TGridPanel
“我正试图在覆盖绘制事件的TGridPanel的每个单元格中绘制。”不清楚?@TomBrunberg,我调整了示例代码以重现我的场景,没有其他依赖项感谢您的帮助。它的解决方案优雅而简单。我仍然对内部面板所占用的空间有问题,这些内部面板在边框内绘制的像素少了1个,即使面板
BorderWidth
=0.@AnselmoMS也感谢您。我不确定是否收到您的评论。您为什么认为面板缺少像素?像素是否在垂直和水平方向上都缺少?也许这应该作为一个新问题发布,特别是如果问题也发生在
GridPanel
之外。
var
  row, col: integer;
  r: TRect;
begin
  ...
  r := CellRect[Col, Row];
  OffsetRect(r, BorderWidth, BorderWidth);