动态创建的button组,如何在实现在点击button2时调用button1的Click 事件?
button2_Click事件处理程序中键入button1.PerformClick();可以调用button1的Click事件,这个我知道;但是动态创建的button组...
button2_Click 事件处理程序中键入button1.PerformClick(); 可以调用button1的Click 事件,这个我知道;
但是动态创建的button组并没有button1/button2这样的区别不是,那请问该如何实现?
创建动态button组的代码如下:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
{
System::Windows::Forms::Button ^button1;
button1=gcnew System::Windows::Forms::Button();
button1->Location = System::Drawing::Point(12+j*30, 12+i*20);
button1->Name = L"button1";
button1->Size = System::Drawing::Size(30, 20);
button1->TabIndex = 0;
button1->Text = L"-";
button1->UseVisualStyleBackColor = true;
button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
this->Controls->Add(button1);
}
} 展开
但是动态创建的button组并没有button1/button2这样的区别不是,那请问该如何实现?
创建动态button组的代码如下:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
{
System::Windows::Forms::Button ^button1;
button1=gcnew System::Windows::Forms::Button();
button1->Location = System::Drawing::Point(12+j*30, 12+i*20);
button1->Name = L"button1";
button1->Size = System::Drawing::Size(30, 20);
button1->TabIndex = 0;
button1->Text = L"-";
button1->UseVisualStyleBackColor = true;
button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
this->Controls->Add(button1);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询