1

マウスの右ボタン クリック イベントを発生させPanel、関数を呼び出そうとしていますが、発生していません。これは私のコードです:

private void viewscreen_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        generate_editpanel();
    }
}

「ビュースクリーン」はPanel. 私のデザイナーコードは次のとおりです。

// viewscreen
// 
this.viewscreen.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.viewscreen.Location = new System.Drawing.Point(208, 16);
this.viewscreen.Name = "viewscreen";
this.viewscreen.Size = new System.Drawing.Size(370, 289);
this.viewscreen.TabIndex = 0;
this.viewscreen.MouseClick += 
    new System.Windows.Forms.MouseEventHandler(this.viewscreen_MouseClick);

誰でも私を助けることができますか?

4

3 に答える 3

1

パネル内のビデオ オブジェクトは、パネルの領域全体 (ドッキング) を覆う必要があります。その場合、すべてのクリックがビデオ オブジェクトで発生するため、パネルのイベントは発生しません。
それでもパネルのイベントを発生させたい場合は、フォーム デザイナーのコードを次のように変更できます。

this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);
this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.viewscreen_MouseClick);  

ここでは、PictureBox(pictureBox1) をパネル (viewscreen) にドッキングしました。そして今、フォームコードで次のようにテストできます:

private void viewscreen_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right) 
        {
            MessageBox.Show(this, "Right Clicked on Panel");
        }            
    }
 private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
    {
        MessageBox.Show(this, "Picture Clicked");
        //this.viewscreen_MouseClick(sender, e);
    }
于 2012-09-14T06:08:10.237 に答える
0

this.viewscreen に関連する完全なコードをここに貼り付けます....そのパネルに他のコントロールがある場合、それらのコントロールはマウスクリックパネルを許可しません。最上位のコントロール イベントが発生します

于 2012-09-14T05:34:57.697 に答える
0

それ以外の ...

private void viewscreen_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        generate_editpanel();
    }
}

これを使って...

private void viewscreen_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            generate_editpanel();
        }
    }

私のために働いています

于 2012-09-15T07:18:13.750 に答える