delphi动态创建tspeedbutton如何写事件?

lam_lau 2013-08-05 04:34:40
delphi动态创建了一组tspeedbutton按钮如何给这些按钮写上OnMouseDown,OnMouseLeave,onClick等事件呢?
...全文
218 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
SQLDebug_Fan 2013-08-05
  • 打赏
  • 举报
回复
事件动态赋值ASpeedBtn.OnMouseDown := ASpeedBtnMouseDown就可以,具体参考2楼的代码,很详细。
sololie 2013-08-05
  • 打赏
  • 举报
回复
高版本的delphi,button 都有OnMouseLeave,speedbutton也不例外。好像d2007(2007都不应该叫高版本了,发布也都7年历史了)开始就有了。 反正就那个意思,LZ俺LS的方法照猫画虎就行了
feiba7288 2013-08-05
  • 打赏
  • 举报
回复
如下:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    ASpeedBtn: TSpeedButton;
    procedure ASpeedBtnClick(Sender: TObject);
    procedure ASpeedBtnMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ASpeedBtnClick(Sender: TObject);
begin
  Memo1.Lines.Add('ASpeedBtnClick');
end;

procedure TForm1.ASpeedBtnMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Memo1.Lines.Add('ASpeedBtnMouseDown');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(ASpeedBtn) then
  begin
    ASpeedBtn := TSpeedButton.Create(Self);
    ASpeedBtn.Parent := Self;
    ASpeedBtn.SetBounds(100, 100, 100, 30);
    ASpeedBtn.Caption := '123';
    ASpeedBtn.OnMouseDown := ASpeedBtnMouseDown;
    //ASpeedBtn.OnMouseLeave := ; //SpeedButton没有这个事件
    ASpeedBtn.OnClick := ASpeedBtnClick;
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(ASpeedBtn) then
    FreeAndNil(ASpeedBtn);
end;

end.

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧