user1321361
user1321361

Reputation: 141

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;
        }
    }
}

Upvotes: 3

Views: 7460

Answers (1)

Alaa Jabre
Alaa Jabre

Reputation: 1903

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

Upvotes: 3

Related Questions