我自己做了一个DBGrid组件叫MyDBGrid,然后我想将我的代码加入到OnDrawDataCell事件中,这样我一用这个组件时就能达到我的目标。但我发现当我重载OnDrawDataCell函数,虽然能达到我的目标,但是组件在窗体中如果再次使用OnDrawDataCell却发现窗体中的事件不能执行了。请问一下,如果我想将的的代理加入我的自定义MyDBGrid组件中,应该怎样做呢
解决方案 »
- 请教:cxgrid如何在单元格中连续输入字符?
- GDI+ TEXTOUT绘制的文字 怎么选中取出来
- Tinydb控件有源码,如何更改Tinytable的字段总数?目前只支持90个,能否修改成支持200个?有修改成功的,望能指点一二
- 求!点击出现日历,然后选择日期为数据库查询条件!我该怎么做啊?
- 放分了
- 这个代码那里出了错误呀???
- 运行fastreport出错了
- 初做B/S结构数据库软件,应注意哪些问题.............
- 我快要急死了,各位大虾,帮帮我吧.一个关于使用QuickRep分页打印的问题
- 如何把进度条放在TStatusBar上
- 求斗地主源码
- 用过VCLskin皮肤控件得看看用在dll窗体调用后再退出程序就报错?
TMyDBGrid = class(TDBGrid)
protected
{ Protected declarations }
procedure DrawDataCell(const Rect: TRect; Field: TField; State: TGridDrawState);override;//这个事件
end;
procedure TMyDBGrid.DrawDataCell(const Rect: TRect; Field: TField; State: TGridDrawState);
begin
...
end;
上面的代码实现组件后,放入Form中就能实现我的目标。
但如果在Form中MyDBGrid的OnDrawDataCell事件却不执行了
应该override消息事件吧,而不是这个
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, ExtCtrls;type
tmypanel=class(tpanel)
public
procedure MouseDown( Button: TMouseButton;Shift: TShiftState; X, Y: Integer);override;
end;
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
ADOQuery1: TADOQuery;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure Mymousedown( Sender: TObject;Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
end;var
Form1: TForm1;
p : tmypanel;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);//测试代码
begin p := tmypanel.Create(nil);
p.OnMouseDown := Mymousedown;
p.Parent := Form1;
p.Left := 400;
p.Top := 300;end;{ tmypanel }procedure tmypanel.MouseDown( Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin Self.Caption := Format('x:%d;y:%d',[x,y]) ;//你把inherited放到前面和后面,你看看效果
inherited;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
p.Free;
end;procedure TForm1.Mymousedown(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
(sender as TPanel).Caption := 'fuck you';
// ShowMessage(Format('x:%d;y:%d',[x,y]));//当inherited放在前面的时候,你把我屏蔽的这一句去掉试试效果。
end;end.