需要使TPanel上的Tabel移动 (100分)

  • 主题发起人 yjiqqukq
  • 开始时间
Y

yjiqqukq

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我的源代码:

unit TextMovedisp;

interface
uses Classes,comctrls,controls,graphics,SysUtils,ExtCtrls,Dialogs,QStdCtrls;

type
TextMove=class(TPanel) //实现字符的移动。
private
FLabel : TLabel;
FEdit:TEdit;
FTimer : TTimer;
FPanel : TPanel;
Finterval : cardinal; //用来设置 FTimer 的 interval
Fcaption : string;

procedure Setcaption(value:string);
procedure Setinterval(value:cardinal);
procedure onTimer(sender:Tobject);

public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property CaptionStr :string read Fcaption write Setcaption;
property interval:cardinal read Finterval write Setinterval;
end;
implementation

procedure TextMove.Setcaption(value:string);
begin
Fcaption:=value;
end;

procedure TextMove.Setinterval(value:cardinal);
begin
Ftimer.Interval :=value;
end;

{procedure TextMove.onTimer; //这是我在没有加 FLabel时做的测试,
begin
FPanel.Align :=alNone;
FPanel.Left :=FPanel.Left -8;
FPanel.Caption :=FCaption;
end; }


constructor TextMove.Create(Aowner:TComponent);
begin
inherited Create(Aowner);
FPanel:=TPanel.Create(self);
FPanel.Parent :=self;
FPanel.Left :=100;
FPanel.Top :=100;
FPanel.Width :=50;
FPanel.Height :=50;
FPanel.Enabled :=true;
FPanel.Visible :=true;
FPanel.Align :=alClient;
FPanel.Color :=clBtnFace;//clRed;
FPanel.Font.Color :=clRed;
Fpanel.Caption :='';

FTimer:= TTimer.Create(nil);
FTimer.Enabled :=true;
FTimer.Interval :=1000;
FTimer.OnTimer :=onTimer ;

FLabel :=TLabel.Create(self);
FLabel.Parent:=FPanel;// //[red]运行到这儿就有问题了     [/red]
FLabel.Left :=100;
FLabel.Top :=0;
FLabel.Width :=50;
FLabel.Height :=50;
FLabel.Font.Color :=clRed;
FLabel.Caption :='好好学习,天天向上';
FLabel.Enabled :=true;
FLabel.Visible :=true;

end;

destructor TextMove.Destroy ;
begin
FLabel.Free;
FTimer.Free;
FPanel.Free ;
inherited Destroy;
end;

end.
 
问题提明确一下!
 
呵呵 对不起了,我现在的问题是:一运行到
FLabel.Parent:=FPanel;// 时就出错了。我的目地是要把label放到Panel.并使它移动。

仍然谢谢你的回答》
:-)
 
奇怪,我实验了一下没有问题,不信你实验一下:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TextMove=class(TPanel) //实现字符的移动。
private
FLabel : TLabel;
// FEdit:TEdit;
FTimer : TTimer;
FPanel : TPanel;
Finterval : cardinal; //用来设置 FTimer 的 interval
Fcaption : string;

procedure Setcaption(value:string);
procedure Setinterval(value:cardinal);
procedure onTimer(sender:Tobject);

public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property CaptionStr :string read Fcaption write Setcaption;
property interval:cardinal read Finterval write Setinterval;
end;


var
Form1: TForm1;
TM: TextMove;

implementation

{$R *.dfm}
procedure TextMove.Setcaption(value:string);
begin
Fcaption:=value;
end;

procedure TextMove.Setinterval(value:cardinal);
begin
Ftimer.Interval :=value;
end;

procedure TextMove.onTimer; //这是我在没有加 FLabel时做的测试,
begin
FPanel.Align :=alNone;
FPanel.Left :=FPanel.Left -8;
FPanel.Caption :=FCaption;
end;


constructor TextMove.Create(Aowner:TComponent);
begin
inherited Create(Aowner);
FPanel:=TPanel.Create(self);
FPanel.Parent :=self;
FPanel.Left :=100;
FPanel.Top :=100;
FPanel.Width :=50;
FPanel.Height :=50;
FPanel.Enabled :=true;
FPanel.Visible :=true;
FPanel.Align :=alClient;
FPanel.Color :=clBtnFace;//clRed;
FPanel.Font.Color :=clRed;
Fpanel.Caption :='';

FTimer:= TTimer.Create(nil);
FTimer.Enabled :=true;
FTimer.Interval :=1000;
FTimer.OnTimer :=onTimer ;

FLabel :=TLabel.Create(self);
FLabel.Parent:=FPanel;// //这运行到这儿就有问题了     
FLabel.Left :=100;
FLabel.Top :=0;
FLabel.Width :=50;
FLabel.Height :=50;
FLabel.Font.Color :=clRed;
FLabel.Caption :='好好学习,天天向上';
FLabel.Enabled :=true;
FLabel.Visible :=true;

end;

destructor TextMove.Destroy ;
begin
FLabel.Free;
FTimer.Free;
FPanel.Free ;
inherited Destroy;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
TM:=TextMove.Create(Self);
TM.Parent:=Self;
TM.SetBounds(0,0,200,200);
end;

end.
 
以前是有错误的。StdCtrls 与QStdCtrls 弄混了。你点 HELP输入TLabel
可以找到两个文件 我是引错了文件。
我现在改进了一下:
unit TextMovedisp;

interface
uses Classes,comctrls,controls,graphics,SysUtils,ExtCtrls
,Dialogs,StdCtrls, QControls;

type
TextMove=class(TPanel) //实现字符的移动。
private
FLabel : TLabel;
FTimer : TTimer;
FPanel : TPanel;
Finterval : cardinal; //用来设置 FTimer 的 interval
Fcaption : string;
//Fcolor: Tcolor;

procedure Setcaption(value:string);
procedure Setinterval(value:cardinal);
procedure onTimer(sender:Tobject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property CaptionStr :string read Fcaption write Setcaption;
property interval:cardinal read Finterval write Setinterval;
end;
implementation

procedure TextMove.Setcaption(value:string);
begin
Fcaption:=value;
FLabel.Caption :=Fcaption;
end;

procedure TextMove.Setinterval(value:cardinal);
begin
Ftimer.Interval :=value;
end;


procedure TextMove.onTimer;
begin
FLabel.left :=FLabel.left -8;
end;


constructor TextMove.Create(Aowner:TComponent);
begin
inherited Create(Aowner);

FTimer:= TTimer.Create(nil);
FTimer.Enabled :=true;
FTimer.Interval :=1000;
FTimer.OnTimer :=onTimer ;

FLabel := TLabel.Create(self);
FLabel.Parent := self;
FLabel.Left :=FLabel.Left +50;
FLabel.Top :=FLabel.Top +10;
FLabel.Font.Color :=clRed;
FLabel.Enabled :=true;
FLabel.Visible :=true;

end;

destructor TextMove.Destroy ;
begin
FLabel.Free;
FTimer.Free;
inherited Destroy;
end;

end.


procedure TForm1.FormCreate(Sender: TObject);
begin
Test:=TextMove.Create(self);

Test.Parent :=self;
Test.Left :=40;
Test.Top :=40;
Test.Width :=425;
Test.Height :=33;
Test.Visible :=true;
Test.Enabled :=true;
Test.interval :=2000;
//Test.Color := clBlack;
Test.CaptionStr :='主车间正常 宾馆正常  俱乐部正常 技术中心正常 ';

end;


多谢你的回答
 
To yjiqqukq
改进了一下:出错,QControls-找不到
删去后,可编译,但出错。
DarwinZhang的没问题,我的改进:
.....
FLabel :=TLabel.Create(self);
FLabel.Parent:=FPanel;// //这运行到这儿就有问题了     
FLabel.Left :=50;
FLabel.Top :=0;
FLabel.Width :=100;
FLabel.Height :=50;
FLabel.Font.Color :=clRed;
FLabel.Font.Name :='宋体';
FLabel.Font.size :=10;
FLabel.Caption :='好好学习,天天向上';
FLabel.Enabled :=true;
FLabel.Visible :=true;
....
 
我看了一下各位的程序算法没有问题,
各位用的QXXXX单元也可以,
不过必须用跨平台编程CLX而不能用VCL,
也就是说必需一致的用CLX或VCL而不能混合.
不信试一下,用菜单:New/CLX Application再:
unit Unit1;

interface

uses
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

TextMove=class(TPanel) //实现字符的移动。
private
FLabel : TLabel;
// FEdit:TEdit;
FTimer : TTimer;
FPanel : TPanel;
Finterval : cardinal; //用来设置 FTimer 的 interval
Fcaption : string;

procedure Setcaption(value:string);
procedure Setinterval(value:cardinal);
procedure onTimer(sender:Tobject);

public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property CaptionStr :string read Fcaption write Setcaption;
property interval:cardinal read Finterval write Setinterval;
end;

var
Form1: TForm1;
TM: TextMove;

implementation

{$R *.xfm}
procedure TextMove.Setcaption(value:string);
begin
Fcaption:=value;
end;

procedure TextMove.Setinterval(value:cardinal);
begin
Ftimer.Interval :=value;
end;

procedure TextMove.onTimer; //这是我在没有加 FLabel时做的测试,
begin
FPanel.Align :=alNone;
FPanel.Left :=FPanel.Left -8;
FPanel.Caption :=FCaption;
end;


constructor TextMove.Create(Aowner:TComponent);
begin
inherited Create(Aowner);
FPanel:=TPanel.Create(self);
FPanel.Parent :=self;
FPanel.Left :=100;
FPanel.Top :=100;
FPanel.Width :=50;
FPanel.Height :=50;
FPanel.Enabled :=true;
FPanel.Visible :=true;
FPanel.Align :=alClient;
FPanel.Color :=clBtnFace;//clRed;
FPanel.Font.Color :=clRed;
Fpanel.Caption :='';

FTimer:= TTimer.Create(nil);
FTimer.Enabled :=true;
FTimer.Interval :=1000;
FTimer.OnTimer :=onTimer ;

FLabel :=TLabel.Create(self);
FLabel.Parent:=FPanel;// //这运行到这儿就有问题了     
FLabel.Left :=100;
FLabel.Top :=0;
FLabel.Width :=50;
FLabel.Height :=50;
FLabel.Font.Color :=clRed;
FLabel.Caption :='好好学习,天天向上';
FLabel.Enabled :=true;
FLabel.Visible :=true;

end;

destructor TextMove.Destroy ;
begin
FLabel.Free;
FTimer.Free;
FPanel.Free ;
inherited Destroy;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
TM:=TextMove.Create(Self);
TM.Parent:=Self;
TM.SetBounds(0,0,200,200);
end;

end.
 
在加以个panel,在panel上反上label1


procedure TForm1.label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

const
SC_DragMove = $F012; // a magic number
begin
ReleaseCapture;
panel1.perform(WM_SysCommand, SC_DragMove, 0);
end;
 
多人接受答案了。
 
呵呵 QControls不用也行,我刚才已删了。
来自:DarwinZhang, 时间:2002-5-1 15:57:00, ID:1079471
奇怪,我实验了一下没有问题,不信你实验一下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
嗯 你看他最后一个。他已经改了。我也是问了才发现的 :-) 我再找一个函数。
让Label 不断的循环 就成了。

 
顶部