研究一下以下的代码,你就可以写出满足你的要求的TDBGridEx了。
其主要是对OnDrawCell事件进行处理......
还不能搞定的话,拿我头去......
type
TMyDBGrid = class(TDBGrid)
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGri
dDrawState); override;
procedure Scroll(Distance: Integer); override;
end; implementation procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState
: TGridDrawState);
var
bmp: TBitmap;
begin
inherited DrawCell(ACol, ARow, ARect, AState);
if ((ARow mod 2)<>0) and (ACol<>0) then
begin
bmp := TBitmap.Create;
try
bmp.Width := ARect.Right - ARect.Left;
bmp.Height:= ARect.Bottom- ARect.Top;
BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
Canvas.Handle, ARect.Left, ARect.Top, SRCCOPY);
bmp.TransparentMode := tmAuto;
bmp.Transparent := True;
Canvas.Brush.Color := clTeal;
Canvas.FillRect(ARect);
Canvas.Draw(ARect.Left, ARect.Top, bmp);
finally
bmp.Free;
end;
end;
end; procedure TMyDBGrid.Scroll(Distance: Integer);
begin
inherited Scroll(Distance);
Repaint;
end;
其主要是对OnDrawCell事件进行处理......
还不能搞定的话,拿我头去......
type
TMyDBGrid = class(TDBGrid)
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGri
dDrawState); override;
procedure Scroll(Distance: Integer); override;
end; implementation procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState
: TGridDrawState);
var
bmp: TBitmap;
begin
inherited DrawCell(ACol, ARow, ARect, AState);
if ((ARow mod 2)<>0) and (ACol<>0) then
begin
bmp := TBitmap.Create;
try
bmp.Width := ARect.Right - ARect.Left;
bmp.Height:= ARect.Bottom- ARect.Top;
BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
Canvas.Handle, ARect.Left, ARect.Top, SRCCOPY);
bmp.TransparentMode := tmAuto;
bmp.Transparent := True;
Canvas.Brush.Color := clTeal;
Canvas.FillRect(ARect);
Canvas.Draw(ARect.Left, ARect.Top, bmp);
finally
bmp.Free;
end;
end;
end; procedure TMyDBGrid.Scroll(Distance: Integer);
begin
inherited Scroll(Distance);
Repaint;
end;
解决方案 »
- TBitmap 存储空间不足,无法处理此命令
- Delphi下点对多的串口编程
- 学习FastReport v3.5 打印条形码
- 在SQL语句怎嵌到DELPHI里面啊?
- 怎样限制MDI窗体只能创建一次 急等
- 我打开了delphi7中的demo例子后,想修改他,可好多控件都没了???
- dephi6.0得报表如果实现a4得横向打印
- 现在做两层的东西,请问怎样用adoconnection怎样连接网络里其他电脑的MS SQL,可以用这东西连接的吗,请问如果可以
- 记录查询匹配的问题?急,急,急!
- DLL中能不能不用ShareMem单元?
- 请问怎么将一个字符转换成ASCLL码?用什么函数?
- 怎么把23000/23的值转成string显示
dbgrid1.canvas.font.color:=ckgreen;
在DBGRID的事件中怎么没有OnDrawCell事件啊?
例如,如果一个城市的人口大于200万,我们就让它显示为蓝色。使用的控件事件为DBGrid.OnDrawColumeCell:
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;