gpt4 book ai didi

C++Builder VCL 按钮数组动态地使每个按钮具有独立的单击操作

转载 作者:行者123 更新时间:2023-11-30 02:54:12 26 4
gpt4 key购买 nike

我已经尝试了以下方法,但它似乎不起作用并且不完整。

void __fastcall TForm1::Button1Click(TObject *Sender) 
{
TButton **ButtonArray = NULL;
ButtonArray = new TButton*[5];

for(int x = 0; x < 5; ++x)
{
ButtonArray[x] = new TButton(this);
ButtonArray[x]->Caption = (AnsiString)"teste " + x + " - " + (1+random(100));
ButtonArray[x]->Left = 25 + 4 * random(100);
ButtonArray[x]->Top = 25 + 4 * random(100);
}
}

代码编译没有问题,但似乎没有按钮显示。此外,数组中没有任何操作,按钮的预定义最大值为 5。

最佳答案

要使它们在您的表单中可见,您必须设置按钮的 Parent 属性。

ButtonArray[ x ]->Parent = this;

没有 Action ,因为你没有设置。

void __fastcall TForm1::ButtonClick(TObject *Sender)
{
MessageBox( Handle, L"Hello", L"Message", MB_OK );
}

在创建按钮时...

ButtonArray[ x ]->OnClick = ButtonClick;

关于C++Builder VCL 按钮数组动态地使每个按钮具有独立的单击操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17274708/

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