我创建了一个用户控制组子类。有两个单选按钮。我需要为他们创建事件处理程序。我有两个方向要走。一种是在子类中创建事件处理程序,并让事件处理程序更改子类中的常量。我将使用一个函数来检查上层类中的子类常量。另一种是在上层类中为子类单选按钮创建事件处理程序。以下是我的方法 1 的代码。注意我已经注释掉了两行(它们是事件处理程序创建),因为它们是错误的,因为它们会产生错误,请帮忙
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::Collections::Generic;
#include <stdio.h>
#include <stdlib.h>
#using <mscorlib.dll>
public ref class temp_groupbox: public GroupBox
{
public: temp_groupbox(int a, int b, String ^groupboxname){
// Create and initialize a GroupBox and two RadioButton controls.
//GroupBox^ groupBox1 = gcnew GroupBox;
RadioButton^ radioButton1 = gcnew RadioButton;
RadioButton^ radioButton2 = gcnew RadioButton;
// Add the RadioButtons to the GroupBox.
this->Controls->Add( radioButton1 );
this->Controls->Add( radioButton2 );
this->Location = System::Drawing::Point(a, b);
this->Size = System::Drawing::Size(500, 100);
this->TabIndex = 0;
this->TabStop = false;
radioButton1->Name = L"radioButton1";
radioButton2->Name = L"radioButton2";
radioButton1->Size = System::Drawing::Size(85, 17);
radioButton2->Size = System::Drawing::Size(85, 17);
radioButton1->Location = System::Drawing::Point(30, 40);
radioButton2->Location = System::Drawing::Point(30, 90);
radioButton1->TabIndex = 0;
radioButton1->TabStop = true;
radioButton2->TabIndex = 1;
radioButton2->TabStop = true;
radioButton1->UseVisualStyleBackColor = true;
radioButton1->CheckedChanged += gcnew System::EventHandler(this, radioButton1_CheckedChanged);
radioButton2->UseVisualStyleBackColor = true;
radioButton2->CheckedChanged += gcnew System::EventHandler(this, radioButton2_CheckedChanged);
this->SuspendLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
public: RadioButton^ radioButton1;
public: RadioButton^ radioButton2;
public: int anss;
void radioButton1_CheckedChanged(Object^ sender, EventArgs^ e)
{
anss = 1;
}
void radioButton2_CheckedChanged(Object^ sender, EventArgs^ e)
{
anss = 2;
}
};// end ref class