请问delphi 的panel 怎么移动啊,就在自己的窗口中移动,不要超出窗口!谢谢!
2个回答
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Panel1: TPanel;
Panel2: TPanel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
// 移动时的偏移值
Xadd: Shortint = 1;
Yadd: Shortint = 1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// 设定Form的相关属性
Panel1.Height := 432;
Panel1.Width := 592;
Panel1.Left := (ClientWidth - Panel1.Width) div 2;
Panel1.Top := (ClientHeight - Panel1.Height) div 2;
Panel2.Height := 32;
Panel2.Width := 32;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// 根据ICON位置变更移动偏移量
if Panel2.Left <= Panel1.Left then
Xadd := 1
else if Panel2.Left + Panel2.Width >= Panel1.Left + Panel1.Width then
Xadd := -1;
if Panel2.Top <= Panel1.Top then
Yadd := 1
else if Panel2.Top + Panel2.Height >= Panel1.Top + Panel1.Height then
Yadd := -1;
// 变更ICON位置
Panel2.Left := Panel2.Left + Xadd;
Panel2.Top := Panel2.Top + Yadd;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Panel1: TPanel;
Panel2: TPanel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
// 移动时的偏移值
Xadd: Shortint = 1;
Yadd: Shortint = 1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// 设定Form的相关属性
Panel1.Height := 432;
Panel1.Width := 592;
Panel1.Left := (ClientWidth - Panel1.Width) div 2;
Panel1.Top := (ClientHeight - Panel1.Height) div 2;
Panel2.Height := 32;
Panel2.Width := 32;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// 根据ICON位置变更移动偏移量
if Panel2.Left <= Panel1.Left then
Xadd := 1
else if Panel2.Left + Panel2.Width >= Panel1.Left + Panel1.Width then
Xadd := -1;
if Panel2.Top <= Panel1.Top then
Yadd := 1
else if Panel2.Top + Panel2.Height >= Panel1.Top + Panel1.Height then
Yadd := -1;
// 变更ICON位置
Panel2.Left := Panel2.Left + Xadd;
Panel2.Top := Panel2.Top + Yadd;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询