请教关于让控件label实现滚动字幕的效果问题
想让单元二中的label的caption属性调用单元一中的Edit中所输入的字符串,这样可以在label控件滚动的时候可以更改caption,实现如同滚动字幕的效果,我的代码可运行,但是label中总是无显示,显示不出Edit中所输入的字符。unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,unit2;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
TestStr:String;{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
TestStr := Edit1.Text;
form2.Show;
end;
end.
-----------------单元分隔----------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm2 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
TestStr:String;
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if label1.Left > -label1.Width then
begin
label1.Caption := TestStr;
label1.Left := label1.left - 5;
end
else
begin
label1.Caption := TestStr;
label1.Left := form2.Width - 35;
end;
end;
end.