无法使用 C++/CLI 在 Windows 表单中的面板中添加按钮
Unable to add buttons in a panel in Windows Form with C++/CLI
我尝试以 windows 形式以编程方式在面板组件中添加按钮,但失败了。
我想在与已制作的其他按钮相同的位置创建按钮。
所以,首先,我制作了一个包含按钮对象的向量。
然后,创建新的 Button 对象并添加到作为按钮父级的面板中。
这就是我使用这个的原因:
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
但这行不通。
获取button的parent的控件对象,应该怎么做?
private: void createButtonDelegate()
{
cliext::vector<Button^> button_contol_list;
button_contol_list.push_back(btn_Connect);
button_contol_list.push_back(btn_Calibration);
button_contol_list.push_back(btn_Frame_Init);
button_contol_list.push_back(btn_Save_Marker_Position);
button_contol_list.push_back(btn_Save_Gripper_Angle);
button_contol_list.push_back(btn_Gripper_Close);
button_contol_list.push_back(btn_Gripper_Open);
button_contol_list.push_back(btn_Test_ETC);
button_contol_list.push_back(btn_Retrieving);
button_contol_list.push_back(btn_Storing);
button_contol_list.push_back(btn_Marker_Detection);
button_contol_list.push_back(btn_Marker_Repeat_Test);
button_contol_list.push_back(btn_Robot_Connect);
button_contol_list.push_back(btn_Cam_Connect);
button_contol_list.push_back(btn_Cam_Calib);
button_contol_list.push_back(btn_EIH_Calib);
for (int i = 0; i < button_contol_list.size(); i++) {
Button^ newButton = gcnew Button();
newButton->Name = "btn_tmp_" + i.ToString();
newButton->Text = "Created Button_" + i.ToString();
newButton->Location = button_contol_list.at(i)->Location;
newButton->Size = System::Drawing::Size(50, 50);
newButton->BringToFront();
newButton->Click += gcnew System::EventHandler(this, &Form1::btn_Initialisation_Click);
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
}
}
我自己找到了解决方案。
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
应该是
button_contol_list.at(i)->Parent->Controls->Add(newButton);
我尝试以 windows 形式以编程方式在面板组件中添加按钮,但失败了。
我想在与已制作的其他按钮相同的位置创建按钮。 所以,首先,我制作了一个包含按钮对象的向量。
然后,创建新的 Button 对象并添加到作为按钮父级的面板中。 这就是我使用这个的原因:
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
但这行不通。 获取button的parent的控件对象,应该怎么做?
private: void createButtonDelegate()
{
cliext::vector<Button^> button_contol_list;
button_contol_list.push_back(btn_Connect);
button_contol_list.push_back(btn_Calibration);
button_contol_list.push_back(btn_Frame_Init);
button_contol_list.push_back(btn_Save_Marker_Position);
button_contol_list.push_back(btn_Save_Gripper_Angle);
button_contol_list.push_back(btn_Gripper_Close);
button_contol_list.push_back(btn_Gripper_Open);
button_contol_list.push_back(btn_Test_ETC);
button_contol_list.push_back(btn_Retrieving);
button_contol_list.push_back(btn_Storing);
button_contol_list.push_back(btn_Marker_Detection);
button_contol_list.push_back(btn_Marker_Repeat_Test);
button_contol_list.push_back(btn_Robot_Connect);
button_contol_list.push_back(btn_Cam_Connect);
button_contol_list.push_back(btn_Cam_Calib);
button_contol_list.push_back(btn_EIH_Calib);
for (int i = 0; i < button_contol_list.size(); i++) {
Button^ newButton = gcnew Button();
newButton->Name = "btn_tmp_" + i.ToString();
newButton->Text = "Created Button_" + i.ToString();
newButton->Location = button_contol_list.at(i)->Location;
newButton->Size = System::Drawing::Size(50, 50);
newButton->BringToFront();
newButton->Click += gcnew System::EventHandler(this, &Form1::btn_Initialisation_Click);
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
}
}
我自己找到了解决方案。
button_contol_list.at(i)->Controls->Owner->Controls->Add(newButton);
应该是
button_contol_list.at(i)->Parent->Controls->Add(newButton);