我想为FORM上所有TEDIT的控件实现MOUSEDOWN事件,如何做?我是这样实现的,可是不成功.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
ListBox1: TListBox;
procedure controlmousedown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.controlmousedown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (button = mbleft) then
(sender as Tcontrol).BeginDrag(false,10);//这个地方并不能实现所有TEDIT类事件?????????????????????????????????????????
end;procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept := source is tcontrol;
end;procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source is tcustomedit then
ListBox1.Items.Add((Source as tcustomedit).Text);
if Source is TLabel then
ListBox1.Items.Add((Source as TLabel).Caption);end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
ListBox1: TListBox;
procedure controlmousedown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.controlmousedown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (button = mbleft) then
(sender as Tcontrol).BeginDrag(false,10);//这个地方并不能实现所有TEDIT类事件?????????????????????????????????????????
end;procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept := source is tcontrol;
end;procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source is tcustomedit then
ListBox1.Items.Add((Source as tcustomedit).Text);
if Source is TLabel then
ListBox1.Items.Add((Source as TLabel).Caption);end;end.
解决方案 »
- 数据库的完整性定义是什么
- 请问怎么让LQ300+切纸
- 救命啊,我的声卡出不了声
- 11
- 数据库的脆弱,请各路高手看一看。
- delphi的代码不能通过,请各位帮忙看看,谢谢
- 500分请教!!高手请进!关于WINDOWS消息及WIN API函数的问题?在线等待!急!!!!!!!
- 高分求救:谁能为我写一段用dbExpress读取mysql 数据的程序代码?
- EncodeLongword问题,请求帮助
- 报表中的标签显示中文的时候乱码,在哪设置?
- 需要输入简单的多行(行中可能含空格)文字,用哪个控件啊?Edit只能输入1行,而RichEdit,memo存入数据库(Access字段类型为"文本"或"备注")时
- 关于AddObject的问题,很奇怪。高手帮忙看看吧!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure myMousedown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.myMousedown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
(sender as TEdit).Text := Format('x:%d;y:%d',[x,y]);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.OnMouseDown := myMousedown;
edit2.OnMouseDown := myMousedown;
edit3.OnMouseDown := myMousedown;
end;end.
上面的例子d7,winxp下测试通过。。onMousedown其实就是一个事件属性,属性,一个指针,访问器而已。参看帮助或者DELPHI的源码,你会发现onmousedown就是一个属性,一个TMouseEven类型的属性。