2

WindowsフォームでC++イベント関数を定義するのに問題があります。

WindowsフォームGUI用に生成されたコードですでにいっぱいになっているWindowsフォーム.hファイルですべての関数定義を行うのではなく、別の.cppファイルでイベント関数(例:ボタンクリック)を定義したいと思います。

私はこれをやってみました、Form1.hクラス内の宣言:

private: System::Void ganttBar1_Paint
(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e);

そして、これはForm1.cppクラス内の定義です。

#include "Form1.h"

System::Void Form1::ganttBar1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
{
    // Definition
}

これを行うと、.cppファイルにクラス名または名前空間名ではないというコンパイラエラーが表示されます。

別のファイルでイベント関数の定義と宣言を取得するにはどうすればよいですか?

私はただ愚かでここで何かが欠けているのですか、それともC ++標準とは別の方法でこれらのことをしなければなりませんか?

4

1 に答える 1

4

クラス定義は、ほとんどの場合、名前空間内にあります(Project1プレースホルダーとして使用します)。

#pragma once

namespace Project1
{
    ref class Form1 : public System::Windows::Forms::Form
    {
        // ...
    };
}

したがって、定義も次のようにする必要があります。

#include "Form1.h"

namespace Project1
{
    void Form1::ganttBar1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
    {
        // definition
    }
}

また

#include "Form1.h"

void Project1::Form1::ganttBar1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
    // definition
}
于 2012-04-24T21:13:14.140 に答える