在Cell中自绘,事件是OnDrawColumnCell
解决方案 »
- 数据库查询出现错误-" 至少有一个参数没被指定值"
- ComboBox去相同记录的问题,请教大家!
- 需要求助了!如何快速将XML数据 转换到 ACCESS 表里。
- 一个窗口中如何设置令一个窗口中某个控件的属性?
- 请问怎么使DBGrid1的栏宽自动适应内容长度?
- 在Delphi+Sql2000中如何通过字段的位置访问字段的值
- 在DELPHI 6中怎样调用自己编写的DLL中的函数?
- [致命错误] ClMain.pas(441): Internal error: C1898
- delphi程序员不用怕:让人期待的Delphi 2007 for Win32
- 如字符中有多个特定符号(如"-"),取去各个"-"的之间字符?
- TSQLConnection不能设置超时,如何让连接时超过一定时间就终止,而不是死在哪里.
- fastreport中没有frxpreview??
http://topic.csdn.net/u/20100323/20/8f742eb6-2ca4-4a0e-9612-9f10d385c4e1.html
在OnDrawCell事件中写下面
with stringgrid1 of
Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小
Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色
Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景
Canvas.FillRect(ARect);
DrawText(self.Canvas.Handle,PChar(self.Cells[ACol,ARow]),Length(self.Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中
end; // }
with stringgrid1 of
Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小
Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色
Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景
Canvas.FillRect(ARect);
DrawText(Canvas.Handle,PChar(Cells[ACol,ARow]),Length(Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ACol = 1 then
begin
StringGrid1.Canvas.Font.Color := clRed;
StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'A');
StringGrid1.Canvas.Font.Color := clBlue;
StringGrid1.Canvas.TextOut(Rect.Left+10,Rect.Top,'B');
StringGrid1.Canvas.Font.Color := clGreen;
StringGrid1.Canvas.TextOut(Rect.Left+20,Rect.Top,'C');
end;
end;