0

ユーザー コントロール グループのサブクラスを作成します。2 つのラジオボタンがあります。それらのイベント ハンドラーを作成する必要があります。私には2つの方向性があります。1 つは、サブクラスでイベント ハンドラーを作成し、イベント ハンドラーでサブクラスの定数を変更できるようにすることです。上位クラスのサブクラス定数を調べる関数を使います。もう 1 つは、サブクラスのラジオ ボタンの上位クラスにイベント ハンドラーを作成することです。以下は、メソッド 1 の私のコードです。2 行 (イベント ハンドラーの作成) をコメント アウトしたことに注意してください。エラーが発生するため間違っているため、助けてください。

    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

ここに画像の説明を入力

4

1 に答える 1

1

メソッドがradioButton1_CheckedChangedあり、radioButton2_CheckedChanged定義されていますか?

void radioButton1_CheckedChanged(Object^ sender, EventArgs^ e)
{
}

void radioButton2_CheckedChanged(Object^ sender, EventArgs^ e)
{
}

これらのメソッドが既に存在する場合は、表示されるエラー メッセージを記載してください。何が問題なのかわからない場合、何かを修正する方法を理解するのは困難です。


デリゲートを作成するメソッドの完全なクラス名を指定し、 を使用し&てそのアドレスを取得する必要があります。

gcnew System::EventHandler(this, &temp_groupbox::radioButton1_CheckedChanged)
于 2012-04-12T23:07:01.343 に答える