变色:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('Population').AsInteger > 20000000 then
DBGrid1.Canvas.Font.Color := clBlue;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('Population').AsInteger > 20000000 then
DBGrid1.Canvas.Font.Color := clBlue;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
解决方案 »
- DELPHI什么控件可以显示邮件文件(.EML)的正文和附件?
- 线程 存储过程使用问题
- delphi 访问网上邻居
- 连接数据库,怎样让数据按时间控件取值!
- 最优网络线路选择,给点思路?
- 求 ExtraPack 源码.
- *****主窗框 .showmodal 如何隐藏?100分重新问!! *******
- Delphi中的初级使用问题
- Borland 如何知道我们编译器的编号呢?
- http://www.hitoday.com/SoftWare/zxiQrReport.zip 提供FOR D5的一套报表组件和一个报表编辑编辑器及源码(做个广告)
- 有答案就给分!!!!
- 寻求既懂delphi 又懂c++Builder的高手来帮忙!帮我翻译一下这段程序!
Name Age Wage
张山 25 500
王武 57 1060
李市 30 520
刘牛 28 390---- 2、创建基于TDBGrid的TColoredDBGrid组件
---- 在Delphi组件菜单中,选择New Component,在弹出对话框中作以下设置: Ancestor Type = TDBGrid
Class Name = TColoredDBGrid---- 然后单击OK按钮,Delphi自动完成组件基本框架的定义。增添OnDRawColoredDBGrid事件并使它出现在Object Inspector的Events中以便在应用程序中设定改变行颜色的条件。重载DrawCell方法,只能自己绘制单元格。不能通过在OnDrawColumnCell来设置颜色,因为在OnDrawColumnCell改变单元格的颜色会再次触发OnDrawColumnCell。 ---- 下面就是所创建组件的源程序 。 ---- 3、建立应用程序进行验证。 ---- 在Delphi文件菜单中选择New建立新的应用程序工程Project1和主窗体Form1,设置Form1的Caption属性为“控制DBGrid行颜色的示例”。在主窗体上添加Data Source、Table、Button和ColoredDBGrid组件。设置各组件的属性如下: Table1.Database=’DBDemos’
Table1.Tablename=’example.db’
Datasource1.Dataset=Table1
ColoredDBGrid1.Datasource=DataSource1
Button1.Caption=’退出’---- 在ColoredDBGrid1的onDRawColoredDBGrid事件中输入下列代码,设定由Wage(工资)来决定在ColoredDBGrid1各行的颜色。
procedure TForm1.ColoredDBGrid1 DRawColoredDBGrid
(Sender: TObject; Field: TField; var Color:
TColor; var Font: TFont);
Var
p : Integer;
begin
p := Table1.FindField('wage').AsInteger;
//取得当前记录的Wage字段的值。
if(p < 500) then begin
//程序将根据wage值设置各行的颜色。
Color := clGreen;
Font.Style := [fsItalic];
//不仅可以改变颜色,还可以改变字体
end;
if(p >= 500) And (p < 800) then
Color := clRed;
if(p >=800) then begin
Color := clMaroon;
Font.Style := [fsBold];
end;
end;
//用‘退出’按钮结束程序运行。
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;