在双击事件里触发DRAWCELL事件, with Stringgrid1 do begin canvas.brush.color:=clred; canvas.fillrect(rect); end;
楼主这样做好象有点问题哦 可以这样实现: 定义一个全局变量:R:TRect; 在DrawCell事件中R:=Rect; 再在StringGrid1DblClick中 : with StringGrid1 do begin canvas.Brush.Color:=clred; canvas.FillRect(R); end; 就可以了!
不知道和DBGrid的方法一样不一样
procedure TForm1.StringGrid1DblClick(Sender: TObject); Const pl=3;//调整可能的偏移 var Rect: TRect; begin with StringGrid1 do begin Form1.Repaint; Rect.Left := DefaultColWidth*Col+GridLineWidth*pl; Rect.Top := DefaultRowHeight*Row+GridLineWidth*pl; Rect.Right := DefaultColWidth*(Col+1)+GridLineWidth*pl; Rect.Bottom := DefaultRowHeight*(Row+1)+GridLineWidth*pl; Canvas.FillRect(Rect); Canvas.Brush.Color := clred; Canvas.Rectangle(Rect); end; end;
先要在stringGrid的SelectCell事件里选到当前点击的cell procedure TfrmTimeIntervalLog.stringGridSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin if ARow <= 0 then exit; intRow := ARow; intCol := ACol; end;然后再如同楼上所说作颜色改变的操作。
with Stringgrid1 do
begin
canvas.brush.color:=clred;
canvas.fillrect(rect);
end;
可以这样实现:
定义一个全局变量:R:TRect;
在DrawCell事件中R:=Rect;
再在StringGrid1DblClick中 :
with StringGrid1 do
begin
canvas.Brush.Color:=clred;
canvas.FillRect(R);
end;
就可以了!
Const pl=3;//调整可能的偏移
var
Rect: TRect;
begin
with StringGrid1 do
begin
Form1.Repaint;
Rect.Left := DefaultColWidth*Col+GridLineWidth*pl;
Rect.Top := DefaultRowHeight*Row+GridLineWidth*pl;
Rect.Right := DefaultColWidth*(Col+1)+GridLineWidth*pl;
Rect.Bottom := DefaultRowHeight*(Row+1)+GridLineWidth*pl;
Canvas.FillRect(Rect);
Canvas.Brush.Color := clred;
Canvas.Rectangle(Rect);
end;
end;
procedure TfrmTimeIntervalLog.stringGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if ARow <= 0 then exit;
intRow := ARow;
intCol := ACol;
end;然后再如同楼上所说作颜色改变的操作。