How to programmatically construct components at runtime using C++ Builder?

房东的猫 提交于 2019-12-19 19:55:31

问题


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;  
}  

Thanks for any help!


回答1:


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

b->Parent = this;


来源:https://stackoverflow.com/questions/15441837/how-to-programmatically-construct-components-at-runtime-using-c-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!