-1

GUIの外観が気に入っているため、C ++ / CLIを使用または「学習」しています。マウスが画像の上にあるときと画像の外にあるときにイベントをトリガーしようとしていますが、機能しません。 、および機能する唯一のイベントは、マウスが画像をクリックしたときです。

私のコードは下にあります

void pictureBox1_MouseEnter(Object^ sender, System::Windows::Forms::MouseEventArgs^ ) {
    label1->Text = String::Concat( sender->GetType(), ": Enter" );
}

void pictureBox1_MouseHover(Object^ sender,  System::Windows::Forms::MouseEventArgs^ ) {
    label1->Text = String::Concat( sender->GetType(), ": MouseHover" );
}

void pictureBox1_MouseLeave(Object^ sender,  System::Windows::Forms::MouseEventArgs^ ) {
    label1->Text = String::Concat( sender->GetType(), ": MouseLeave" );
}

private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
    label1->Text = String::Concat( sender->GetType(), ": Click" );
}
4

2 に答える 2

0

たぶんあなたはそれらのメソッドをコールバックとして追加するのを忘れていました

于 2013-03-26T16:45:54.837 に答える
0

それがコード全体である場合は、いくつかのメソッドを定義するだけです。UIは、これらのイベントが発生したときにそれらを呼び出すことになっていることを認識していません。

必要なのは、さまざまなオブジェクトにイベントハンドラーを追加することです。ローカルメソッドからデリゲートを作成し、それを(+=演算子を使用して)イベントに追加します。

MouseEnterMouseHover、およびMouseLeaveはすべて、 MouseEventHandlerではなくEventHandlerとして定義されています。つまり、メソッドはMouseEventArgsではなくEventArgsを受け取る必要があるため、メソッド宣言を切り替えます。

// Do this in the constructor.
this->pictureBox1->MouseEnter += gcnew EventHandler(this, &Form1::pictureBox1_MouseEnter);
this->pictureBox1->MouseHover += gcnew EventHandler(this, &Form1::pictureBox1_MouseHover);
this->pictureBox1->MouseLeave += gcnew EventHandler(this, &Form1::pictureBox1_MouseLeave);

this->pictureBox1->Click += gcnew EventHandler(this, &Form1::pictureBox1_Click);
于 2013-03-26T16:54:17.133 に答える