群里有人发出这么个需求,说是鼠标按住不放的同时开始计数累加1,放掉归零。
delphi 中没有鼠标按住不放的属性,只能借助MouseDown,Mouseup,加timer来实现了。
timer设置时间周期为50,可以随意调整。
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Edit1: TEdit;
- Timer1: TTimer;
- procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Timer1Timer(Sender: TObject);
- procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- var s:Integer;
- {$R *.dfm}
- procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- Timer1.Enabled:=true;
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- begin
- s:=s+1;
- edit1.Text:=IntToStr(s);
- end;
- end;
- procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- Timer1.Enabled:=False;
- s:=0;
- Edit1.Text:='0';
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Timer1.Enabled:=False;
- end;
- end.
0 条评论
沙发空缺中,还不快抢~