如何使用C ++ Builder在运行时以编程方式构造组件? [英] How to programmatically construct components at runtime using C++ Builder?

查看:80
本文介绍了如何使用C ++ Builder在运行时以编程方式构造组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常基本的C ++ Builder问题。我想在运行时创建一个TButton。我以为下面的代码可以做到,但是我在表单上看不到任何按钮:

Very basic C++ Builder question. I want to create a TButton at runtime. I would have thought that the following code would do it, but I see no button on the form:

__fastcall TForm2::TForm2(TComponent* Owner): TForm(Owner)  
{  
    TButton* b = new TButton(this);  
    b->Height = 100;  
    b->Width = 100;  
    b->Left = 0;   
    b->Top = 0;   
    b->Caption = "Testing";  
    b->Visible = true;  
    b->Enabled = true;  
}  

感谢您的帮助!

推荐答案

您需要设置按钮的 Parent (其显示的表面):

You need to set the button's Parent (the surface it displays on):

b->Parent = this;

这篇关于如何使用C ++ Builder在运行时以编程方式构造组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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