DBGrid DrawDataCell
来源:互联网 发布:ubuntu 16.04 卸载qq 编辑:程序博客网 时间:2024/05/23 13:24
//前提是 DBGrid 的 Columns 对象的属性是由 DataSet 自动生成,利用Canvas对象,在 DrawDataCell 事件中加入处理代码。
//例子如下(以 在竖直方向填充渐进色为例 ):
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var iClVal: Word; //控制颜色Red、Green、Blue 各自值的变量
ClVal1, ClVal1: Integer; //渐进色两个端色的变化范围
yStep, y: Real; //yStep 为竖直方向颜色跨度, y 为竖直方向画笔的 相对坐标(非绝对坐标)
RectWidth, RectHeight: Integer; //正在 Draw 事件中对应的 Cell 区域的宽和高
Tx, Ty: Integer; //文字放置位置的相对坐标
begin
//端色值差距要足够大,否则可能造成添色不全
ClVal1 := 50;
ClVal2 := 250;
Tx := 10;
Ty := 15;
RectWidth := Rect.Right - Rect.Left;
RectHeight := Rect.Bottom - Rect.Top;
yStep:= RectHeight / 256; //除以256是因为 RGB 颜色中三色的最大值为 255
y:= 0;
for iClVal := ClVal1 to ClVal2 do
begin
DBGrid1.Canvas.Brush.Color:=RGB(iWord+10,iWord-20,iWord-15); //此处置简单地以固定常量变化确定R、G、B三色的偏移量,实际中可编写偏移函数进行复杂渐变。
DBGrid1.Canvas.FillRect(Classes.Bounds(Rect.Left + 0, Rect.Top + Round(y), (Rect.Right - Rect.Left), Round(y + yStep)));
y:=y + yStep; //移动画笔的 竖直相对坐标
end;
//以上为渐进色添入过程,要在 Cell 中显示文字,应在上述代码完成后,加入如下代码:
DBGrid1.Canvas.Brush.Style:=Graphics.bsClear; //改变画笔类型,如省略此步,显示文字的区域将有背景色,即文字区域不透明
//上句中, Graphics 不可省,否则 IDE 可能将 bsClear 视为 QGraphics 的TBrushStyle常量, 造成编译含糊。
DBGrid1.Canvas.TextOut(Rect.Left + Tx, Rect.Top + Ty, Field.AsString);
end;
///(当 Columns 属性并非由 DataSet 自动生成时,改为在 DrawColumnCell 事件中加入处理代码) ,如下:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var iClVal: Word; //控制颜色Red、Green、Blue 各自值的变量
ClVal1, ClVal1: Integer; //渐进色两个端色的变化范围
yStep, y: Real; //yStep 为竖直方向颜色跨度, y 为竖直方向画笔的 相对坐标(非绝对坐标)
RectWidth, RectHeight: Integer; //正在 Draw 事件中对应的 Cell 区域的宽和高
Tx, Ty: Integer; //文字放置位置的相对坐标
begin
//端色值差距要足够大,否则可能造成添色不全
ClVal1 := 50;
ClVal2 := 250;
Tx := 10;
Ty := 15;
RectWidth := Rect.Right - Rect.Left;
RectHeight := Rect.Bottom - Rect.Top;
yStep:= RectHeight / 256; //除以256是因为 RGB 颜色中三色的最大值为 255
y:= 0;
for iClVal := ClVal1 to ClVal2 do
begin
DBGrid1.Canvas.Brush.Color:=RGB(iWord+10,iWord-20,iWord-15); //此处置简单地以固定常量变化确定R、G、B三色的偏移量,实际中可编写偏移函数进行复杂渐变。
DBGrid1.Canvas.FillRect(Classes.Bounds(Rect.Left + 0, Rect.Top + Round(y), (Rect.Right - Rect.Left), Round(y + yStep)));
y:=y + yStep; //移动画笔的 竖直相对坐标
end;
//以上为渐进色添入过程,要在 Cell 中显示文字,应在上述代码完成后,加入如下代码:
DBGrid1.Canvas.Brush.Style:=Graphics.bsClear; //改变画笔类型,如省略此步,显示文字的区域将有背景色,即文字区域不透明
//上句中, Graphics 不可省,否则 IDE 可能将 bsClear 视为 QGraphics 的TBrushStyle常量, 造成编译含糊。
DBGrid1.Canvas.TextOut(Rect.Left + Tx, Rect.Top + Ty, Column.Field.AsString);
end;
//例子如下(以 在竖直方向填充渐进色为例 ):
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var iClVal: Word; //控制颜色Red、Green、Blue 各自值的变量
ClVal1, ClVal1: Integer; //渐进色两个端色的变化范围
yStep, y: Real; //yStep 为竖直方向颜色跨度, y 为竖直方向画笔的 相对坐标(非绝对坐标)
RectWidth, RectHeight: Integer; //正在 Draw 事件中对应的 Cell 区域的宽和高
Tx, Ty: Integer; //文字放置位置的相对坐标
begin
//端色值差距要足够大,否则可能造成添色不全
ClVal1 := 50;
ClVal2 := 250;
Tx := 10;
Ty := 15;
RectWidth := Rect.Right - Rect.Left;
RectHeight := Rect.Bottom - Rect.Top;
yStep:= RectHeight / 256; //除以256是因为 RGB 颜色中三色的最大值为 255
y:= 0;
for iClVal := ClVal1 to ClVal2 do
begin
DBGrid1.Canvas.Brush.Color:=RGB(iWord+10,iWord-20,iWord-15); //此处置简单地以固定常量变化确定R、G、B三色的偏移量,实际中可编写偏移函数进行复杂渐变。
DBGrid1.Canvas.FillRect(Classes.Bounds(Rect.Left + 0, Rect.Top + Round(y), (Rect.Right - Rect.Left), Round(y + yStep)));
y:=y + yStep; //移动画笔的 竖直相对坐标
end;
//以上为渐进色添入过程,要在 Cell 中显示文字,应在上述代码完成后,加入如下代码:
DBGrid1.Canvas.Brush.Style:=Graphics.bsClear; //改变画笔类型,如省略此步,显示文字的区域将有背景色,即文字区域不透明
//上句中, Graphics 不可省,否则 IDE 可能将 bsClear 视为 QGraphics 的TBrushStyle常量, 造成编译含糊。
DBGrid1.Canvas.TextOut(Rect.Left + Tx, Rect.Top + Ty, Field.AsString);
end;
///(当 Columns 属性并非由 DataSet 自动生成时,改为在 DrawColumnCell 事件中加入处理代码) ,如下:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var iClVal: Word; //控制颜色Red、Green、Blue 各自值的变量
ClVal1, ClVal1: Integer; //渐进色两个端色的变化范围
yStep, y: Real; //yStep 为竖直方向颜色跨度, y 为竖直方向画笔的 相对坐标(非绝对坐标)
RectWidth, RectHeight: Integer; //正在 Draw 事件中对应的 Cell 区域的宽和高
Tx, Ty: Integer; //文字放置位置的相对坐标
begin
//端色值差距要足够大,否则可能造成添色不全
ClVal1 := 50;
ClVal2 := 250;
Tx := 10;
Ty := 15;
RectWidth := Rect.Right - Rect.Left;
RectHeight := Rect.Bottom - Rect.Top;
yStep:= RectHeight / 256; //除以256是因为 RGB 颜色中三色的最大值为 255
y:= 0;
for iClVal := ClVal1 to ClVal2 do
begin
DBGrid1.Canvas.Brush.Color:=RGB(iWord+10,iWord-20,iWord-15); //此处置简单地以固定常量变化确定R、G、B三色的偏移量,实际中可编写偏移函数进行复杂渐变。
DBGrid1.Canvas.FillRect(Classes.Bounds(Rect.Left + 0, Rect.Top + Round(y), (Rect.Right - Rect.Left), Round(y + yStep)));
y:=y + yStep; //移动画笔的 竖直相对坐标
end;
//以上为渐进色添入过程,要在 Cell 中显示文字,应在上述代码完成后,加入如下代码:
DBGrid1.Canvas.Brush.Style:=Graphics.bsClear; //改变画笔类型,如省略此步,显示文字的区域将有背景色,即文字区域不透明
//上句中, Graphics 不可省,否则 IDE 可能将 bsClear 视为 QGraphics 的TBrushStyle常量, 造成编译含糊。
DBGrid1.Canvas.TextOut(Rect.Left + Tx, Rect.Top + Ty, Column.Field.AsString);
end;
- DBGrid DrawDataCell
- Delphi中关于DBGrid的DrawDataCell和DrawColumnCell的触发条件
- dbgrid
- DBGrid排序
- Coloring DBGrid
- DBGrid 应用全书(一)
- DBGrid使用全书(二)
- DBGrid使用全书(三)
- DBGrid使用全书(四)
- DBGrid使用全书(五)
- DBGrid的色彩
- DBGrid 应用全书
- DBGrid 应用系列
- 拷贝DBGrid当前行
- DBGrid 单击弹出PickList
- DBGrid控件大全(一)
- Dbgrid 当前行颜色
- DBGrid 应用全书
- Reset CSS:只选对的,不选"贵"的
- debian下普通用户wireshark 抓包的问题
- Arcgis Engnie 汽车沿线路行走
- Trufun云端建模平台之云端UML工具发布
- C# access 提示update语法错误
- DBGrid DrawDataCell
- C++ Virtual关键字的非常规使用
- oracle 管理控制文件
- C#进化史
- hdu1078 zoj1107(记忆化搜索/DP)
- 通过手机远程关机
- Delphi7控件包列表
- Android Wi-Fi Display(Miracast)介绍
- XCode 4 的调试定位技巧