改变当前行的颜色
在StringGrid1.Options中要包含goRowSelect
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
with Canvas do
begin
if (ARow=Row)and(ACol>=FixedCols) then
Brush.Color:=clRed
else
if (ARow>=FixedRows)and(ACol>=FixedCols) then Brush.Color:=clWhite;
FillRect(Rect);
end;end;end.
在StringGrid1.Options中要包含goRowSelect
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
with Canvas do
begin
if (ARow=Row)and(ACol>=FixedCols) then
Brush.Color:=clRed
else
if (ARow>=FixedRows)and(ACol>=FixedCols) then Brush.Color:=clWhite;
FillRect(Rect);
end;end;end.
解决方案 »
- 鼠标放置,不点击,图片变换
- 如何通过Delphi技术高速导入数据量很大的XML数据文件?
- 每一个实验,失败了.朋友们帮忙看看.
- 郁闷了好久~~~ado访问access出现语法错误?
- 关于在程序中实现对Word模板的调用
- 如果你对自己心爱的女孩子坦白. 她用如下的理由来拒绝, 你会怎么说? 如何说又是最好?
- 一个delphi初学者的问题.
- 在三层结构中,我想在客户端体现出主从表的记录,就象两层的一样,主表变化,从表也变化,应该怎么实现??谢谢。
- ??? 如何查找TXT中内容 ???
- 数据库的一个问题
- ==如何用QuickRpt打印这样的图表?===
- 问一个菜鸟问题:如何关闭我得delphi程序,有几种方法?
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;
type TMyGrid=class(TStringGrid)
end;假设该grid叫 StringGrid1 ,它的DefaultDrawing属性必须为true
写它的OnDrawCell事件:if(ARow=2)and(ACol>0)then //将第2行的背景变成红色
begin
StringGrid1.Canvas.Brush.Color:=clRed;
StringGrid1.Canvas.FillRect(Rect); //画红色
StringGrid1.OnDrawCell:=nil; //设置为nil,下面就不会无限递归
try
TMyGrid(StringGrid1).DrawCell(ACol,ARow,Rect,State);
finally
StringGrid1.OnDrawCell:=StringGrid1DrawCell; //恢复事件的地址
end;
end;