如何动态创建自定义TabSheet运行时 [英] How to dynamically create customized TabSheet runtime

查看:214
本文介绍了如何动态创建自定义TabSheet运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个必须在运行时创建的TTabsheet。 TTabSheet有几个组件,但是所有这些组件在每个选项卡上都是相同的。是否可以创建一个type变量,每次都会创建这些选项卡?

I would like to create a TTabsheet which has to be create during run time. The TTabSheet has several components, but all of these components will be identical on every tab. Is it possible to create a "type" variable which will create these tabs every time?

谢谢

推荐答案

是的。您可以从TTabSheet创建继承的类

Yes. You could create inherited class from TTabSheet

TCustomTabSheet = class(TTabSheet)
public
  constructor Create(AOwner : TComponent); override;
public
   FTestButton : TButton;
end;

constructor TCustomTabSheet.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FTestButton := TButton.Create(Self);
  FTestButton.Parent := Self;
  FTestButton.Left := 1;
  FTestButton.Top := 1;
  FTestButton.Width := 20;
  FTestButton.Heigth := 10;
  FTestButton.Caption := 'Cool button!';
  FTestButton.Name := 'TestButton';
end;

您还可以在设计时使用自定义控件创建一个框架(TFrame),并将其实例托管所有新标签页。

You could also create a frame (TFrame) with your custom controls in design time and host it instances to all new tabs.

这篇关于如何动态创建自定义TabSheet运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆