问题
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