我把一个adoquery中的select出来的集合通过stringgrid显示出来。
但是某些特定的记录我想把它们用红颜色表示。
比如我想把adoquuery1.fieldbyname(mark).asstring:=y
的记录行用红颜色表示,另外,这一个字段我不想在stringgrid中显出,
怎么处理法?
如果是男孩那就算了,女孩嘛,赫赫,
首先,你必须一个一个得单元格设置如
tempStr:=stringgrid1.Cells[ACol,ARow];
with stringgrid1.Canvas do
begin
StrHeight:=TextHeight(tempStr);
Brush.Color:=RGB(100,128,192);
FillRect(Rect);
Pen.Color:=RGB(192,192,192);
Pen.Width:=1;
Rectangle(Rect);
Font.Color:=RGB(0,0,200);
Font.Style:=[fsBold];
TextOut(Rect.Left+2,Rect.+(Rect.Bottom-Rect.-StrHeight) div 2,tempStr);
end;
如果不想让这个字段显示,那就不要将这个字段与stringgrid结合就是了喔。
只将文字变红:用下面一段程序,保你满意:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var Area:TRect;
begin
if ARow = 1 then
with StringGrid1,StringGrid1.Canvas do begin
FillRect(Rect);
Font.Color := clRed;
Area:= Rect;
InflateRect(Area, -2, -2);
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER);
end;
end;