TSpeedButton?

Fallingstar 2002-10-13 04:07:37
怎样添加TSpeedButton控件?
...全文
107 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Drate 2002-10-13
  • 打赏
  • 举报
回复
刚才的代码有点问题,这是正确的,经DELPHI6测试通过:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;

//动态按钮的响应事件
Procedure buttononclick(Sender:TObject);

procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.buttononclick(Sender: TObject);
begin
case TSpeedButton(Sender).Tag of
1: showmessage('This is Test1');
2: showmessage('This is Test2');
end;
end;



procedure TForm1.FormCreate(Sender: TObject);
var
ButtonTest:TSpeedButton;
btntop,
btnleft:Integer;

begin
btntop:=10;
btnleft:=10;
ButtonTest:=TSpeedButton.Create(Self);
With ButtonTest do
begin
tag:=1;
Caption:='test1';
parent:= self;
Top:=btntop;
Left:=btnleft;
onclick := buttononclick;
end;

btntop:=100;
btnleft:=100;
ButtonTest:=TSpeedButton.Create(Self);
With ButtonTest do
begin
tag:=2;
Caption:='test2';
parent:= self;
Top:=btntop;
Left:=btnleft;
onclick := buttononclick;
end;
end;

end.
Drate 2002-10-13
  • 打赏
  • 举报
回复
不知道楼主说的是个什么添加法,如果是动态添加的话,我这里是一个演示的代码:

unit Unit1;

interface

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

type
TForm1 = class(TForm)

//动态按钮的响应事件
Procedure buttononclick(Sender:TObject);

procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.buttononclick(Sender: TObject);
begin
case TSpeeedButton(Sender).Tag of
1: showmessage('This is Test1');
2: showmessage('This is Test2');
end;
end;



procedure TForm1.FormCreate(Sender: TObject);
var
ButtonTest:TSpeeedButton;
btntop,
btnleft:Integer;

begin
btntop:=10;
btnleft:=10;
ButtonTest:=TButton.Create(Self);
With ButtonTest do
begin
tag:=1;
Caption:='test1';
parent:= self;
Top:=btntop;
Left:=btnleft;
onclick := buttononclick;
end;

btntop:=100;
btnleft:=100;
ButtonTest:=TButton.Create(Self);
With ButtonTest do
begin
tag:=2;
Caption:='test2';
parent:= self;
Top:=btntop;
Left:=btnleft;
onclick := buttononclick;
end;
end;

end.


如果是静态添加的话,可就是在你的控件面板上找到“Additional”中的第二项就是speedbutton了
M16 2002-10-13
  • 打赏
  • 举报
回复
with TSpeedButton.create(self) do

5,929

社区成员

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

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