var
x, i, j, w, h: integer;
rect1: TRect;
begin
i := 3;
//列
j := 4;
//行
w := 0;
h := 0;
for x := 0 to i-1 do
w := w + StringGrid1.ColWidths[x] + StringGrid1.GridLineWidth;
for x := 0 to j-1 do
h := h + StringGrid1.RowHeights[x] + StringGrid1.GridLineWidth;
with rect1 do
begin
Left := w;
Top := h;
Right := Left + StringGrid1.ColWidths + StringGrid1.GridLineWidth;
Bottom := Top + StringGrid1.RowHeights[j] + StringGrid1.GridLineWidth;
end;
StringGrid1.Canvas.Brush.Color := clRed;
StringGrid1.Canvas.FillRect(rect1);
end;
要不就
procedure TForm1.StringGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
begin
with StringGrid1 do
begin
if (ACol = 3) and (ARow = 3) then
begin
Canvas.Brush.Color := clRed;
Canvas.FillRect(Rect);
Canvas.Font.Name := 'Courier New';
Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
end;
end;
end;