看看行不行..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MouseMoveAndMouseLeave
{
public partial class Form1 : Form
{
private bool isMouseInPanel;
private bool isMouseInButton;
public event EventHandler OnMouseLeavePanelRegion;
public Form1()
{
InitializeComponent();
this.panel1.BorderStyle = BorderStyle.Fixed3D;
this.isMouseInButton = true;
this.isMouseInPanel = false;
this.panel1.MouseLeave += new EventHandler(panel1_MouseLeave);
this.panel1.MouseEnter += new EventHandler(panel1_MouseEnter);
this.button1.MouseEnter += new EventHandler(button1_MouseEnter);
this.button1.MouseLeave += new EventHandler(button1_MouseLeave);
this.OnMouseLeavePanelRegion += new EventHandler(Form1_OnMouseLeavePanelRegion);
}
void button1_MouseLeave(object sender, EventArgs e)
{
this.isMouseInButton = false;
}
void Form1_OnMouseLeavePanelRegion(object sender, EventArgs e)
{
if (!this.isMouseInButton && !this.isMouseInPanel)
{
this.panel1.Visible = false;
}
}
void button1_MouseEnter(object sender, EventArgs e)
{
this.isMouseInButton = true;
}
void panel1_MouseEnter(object sender, EventArgs e)
{
this.isMouseInPanel = true;
this.OnMouseLeavePanelRegion(null, null);
}
void panel1_MouseLeave(object sender, EventArgs e)
{
this.isMouseInPanel = false;
this.OnMouseLeavePanelRegion(null, null);
}
}
}