我用如下方法画了颜色
StringGrid1.Canvas.brush.Color:=clred;
StringGrid1.Canvas.FillRect(stringGrid1.CellRect(1,1);
当有一个窗口刷过StringGrid1上面画的颜色就没有了,有什么好办法可以使上面的颜色不会被刷取
StringGrid1.Canvas.brush.Color:=clred;
StringGrid1.Canvas.FillRect(stringGrid1.CellRect(1,1);
当有一个窗口刷过StringGrid1上面画的颜色就没有了,有什么好办法可以使上面的颜色不会被刷取
type
TStringGridEx = class(TStringGrid);procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if not ((ACol = 1) and (ARow = 1)) then Exit;
TStringGridEx(Sender).OnDrawCell := nil;
try
TStringGridEx(Sender).Canvas.Brush.Color := clYellow;
TStringGridEx(Sender).DrawCell(ACol, ARow, Rect, State);
finally
TStringGridEx(Sender).OnDrawCell := StringGrid1DrawCell;
end;
end;
如果看不到效果,就贴出调试的代码,好给你分析StringGrid1.Canvas.brush.Color:=clred;
StringGrid1.Canvas.FillRect(stringGrid1.CellRect(1,1);
两条代码我还花时间问吗?
我是根据一个比较耗时的查询语句检测是否标为红色,而Stringgrid的OnDrawCell事件每次刷新都要重绘,要是每次重绘都执行查询语句会影响速度所以我将重绘颜色放在Button的clck事件中请问有什么好的解决办法吗
vCol, vRow: Integer;procedure TForm1.Button1Click(Sender: TObject);
begin
{ TODO : 执行查询语句 }
{ TODO : 得到vCol, vRow }
StringGrid1.Repaint;
end;type
TStringGridEx = class(TStringGrid);procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if not ((ACol = vCol) and (ARow = vRow)) then Exit;
TStringGridEx(Sender).OnDrawCell := nil;
try
TStringGridEx(Sender).Canvas.Brush.Color := clYellow;
TStringGridEx(Sender).DrawCell(ACol, ARow, Rect, State);
finally
TStringGridEx(Sender).OnDrawCell := StringGrid1DrawCell;
end;
end;