1.属性:DrawAutomatic = False.
2.create a method for the OnDrawCell event.The OnDrawCell event would look something like:
var
Text: array[0..255] of Char;
begin
StrPCopy (Text, StringGrid1.Cells[Row, Col]);
if Col = 2 then
StringGrid1.Canvas.Brush.Color := clYellow
else
StringGrid1.Canvas.Brush.Color := clWhite;
ExTextOut (..., Rect.Left + 2, Rect.Bottom + 2, ..., Text, StrLen (Text));
end;上面的代码将第三行画成黄色,其他为白色。(参考:GRIDS.PAS - VCL原代码)
2.create a method for the OnDrawCell event.The OnDrawCell event would look something like:
var
Text: array[0..255] of Char;
begin
StrPCopy (Text, StringGrid1.Cells[Row, Col]);
if Col = 2 then
StringGrid1.Canvas.Brush.Color := clYellow
else
StringGrid1.Canvas.Brush.Color := clWhite;
ExTextOut (..., Rect.Left + 2, Rect.Bottom + 2, ..., Text, StrLen (Text));
end;上面的代码将第三行画成黄色,其他为白色。(参考:GRIDS.PAS - VCL原代码)
解决方案 »
- 2000元求购江苏省<<毕业生就业协议书>>!有效期4天!
- 好多年不提问了,今天问个问题
- 如何检测网线被拔下、网卡被禁用?局域网内本机网络是否正常工作????
- 请问我的用代码生成combobox控件的程序,为什么MyCombobox.Style :=csDropDownList这句会报错???
- 怎样用最快的方法检测数据库是否连通?
- Delphi 7.0 用DBEXPRESS连接Oracle的时候报错Unable to Load oci.dll.:
- 在线等待(MDI)显示子窗体
- 繁体中文开发的问题!
- 使用InputBox输入口令,要在输入框中显示全为"*",怎么办?
- sql中有参数,是这么用吗?请指点.
- 超时与机算机名或IP地址有很大关系吗
- 难道真的没有Delphi和数据库的高手吗?分数赠英雄!
大哥,你说的我已作到了,我要的是这个string的颜色,最起码这个string所在单元格颜色,而不是这一行,再指点指点,多谢!
If ( Cells[Col, Row] = '中国' ) Then
Canvas.Font.Color := clRed
Else
Canvas.Font.Color := clBlack;
ExTextOut (..., Rect.Left + 2, Rect.Bottom + 2, ..., Text, StrLen (Text));
Rect: TRect; State: TGridDrawState);
begin
//根据你的条件选择要特殊显示的ACol, ARow
//设置Canvans.Color
TextRect(Rect, Rect.Left, Rect.Top, Cells[ACol, ARowl]);
(Sender as TstringGrid).Invalidiate;
end;