任意打印
有时我们要打印任意排列的表或往已经印好的登记表上对号入座写上数据时,可
以新建一个窗体(假设为Form1),再把Form1的BorderStyle设为bsNone、AutoScroll
设为True,接下来再创建一个新窗体(假设为Form2),再建个按钮Button1,编写代
码:
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Width :=900;
Form1.Height :=800;
Form1.Print;
end;
接下来你在Form1上对应的位置写上数据,运行后按Button1就会一五一十的打印
下来了。
运行时生成控件
㈠、运行时生成可视控件:以下以TEdit 控件为例
1.在Form的Public中定义TEdit控件
Edit1:TEdit;
2.在需要生成的地方加入以下代码:
Edit1:=TEdit.Create(Self);
Edit1.Parent:=Form1;
Edit1.Left ?:=20;
Edit1.Top :=20;
Edit1.Text :='Edit1 Text';
3.使用完毕后,释放分配的资源
if? Assigned(Edit1) then Edit1.Free; ?
㈡、运行时生成非可视控件:以下以 TTimer控件为例
1.在Form的Public中定义TTimert控件
Timer1:TTimber;
2.在需要生成的地方加入以下代码:
Timer1:=TTimer.Create(Self);
Timer1.OnTimer:=YourAction;
YourAction是自己定义的OnTimer事件,使用
procedure TForm1.YourAction(Sender:TObject); 完成
3.使用完毕后,释放分配的资源
if? Assigned(Timer1) then Timer1.Free; ?
