gpt4 book ai didi

runtime - 如何使用 C++ Builder 在运行时以编程方式构造组件?

转载 作者:行者123 更新时间:2023-12-02 21:19:28 25 4
gpt4 key购买 nike

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

__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(它显示的表面):

b->Parent = this;

关于runtime - 如何使用 C++ Builder 在运行时以编程方式构造组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com