C ++ Builder VCL按钮数组通过其独立的单击动作来动态生成每个按钮 [英] C++Builder VCL array of buttons dynamically made each with his independent click action

查看:70
本文介绍了C ++ Builder VCL按钮数组通过其独立的单击动作来动态生成每个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have tried the following way but it doesn't seem to work and it is incomplete.

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。

Code compiles without problems, but no button seems to show. Also, there is no action and buttons in the array have a predefined max of 5.

推荐答案

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

To make them visible in your form you must set the Parent property of your buttons.

ButtonArray[ x ]->Parent = this;

没有任何动作,因为您没有设置一个。

There's no action because you do not set one.

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

在创建按钮时...

ButtonArray[ x ]->OnClick = ButtonClick;

这篇关于C ++ Builder VCL按钮数组通过其独立的单击动作来动态生成每个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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