高手请进分大大的有(100分)

  • 主题发起人 主题发起人 lwgygz
  • 开始时间 开始时间
L

lwgygz

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何改变StringGrid的某一格的颜色?
 
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;
 
后退
顶部