简体   繁体   中英

Visual C# mouse events on a panel not firing

I'm using Visual C# 2008 and am stuck with mouse events on a panel. I have defined a mouse down, mouse leave, mouse enter. I made it very simple.

I pressed on the panel selected those events I needed and it auto generated my needed code for firing a mouse events.

Inserted a breakpoint in my recieving eventcode, but it will never be firing.

Is there a bug in Visual C#? I can't find what I'm doing wrong.

Some code, Form1.Designer :

this.pagepanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pagepanel_MouseDown);
this.pagepanel.MouseEnter += new System.EventHandler(this.pagepanel_MouseEnter);
this.pagepanel.MouseLeave += new System.EventHandler(this.pagepanel_MouseLeave);

Form1.cs:

private void pagepanel_MouseLeave(object sender, EventArgs e) =>
    this.Cursor = Cursors.Default;
private void pagepanel_MouseEnter(object sender, EventArgs e) =>
    this.Cursor = Cursors.WaitCursor;

private void pagepanel_MouseDown(object sender, MouseEventArgs e)
{
    if (mode == MODE_BUTTON)
    {
        int x = e.X;
        int y = e.Y;

        switch (e.Button)
        {
            case MouseButtons.Right: break;
            case MouseButtons.Left:   break;
            case MouseButtons.Middle: break;
        }
    }
}

Make sure your panel is in the front. Use bring to front in the designer. Maybe another container control is getting in the way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM