C#窗体动态添加用户控件,想要实现鼠标离开用户控件所在区域删除用户控件,这里我用的是MouseLeave,但是运行时,鼠标不论里没离开控件,都触发了用户控件的MouseLeave事件,这是为什么?
该用户控件为组合控件,没有人为定义任何事件。
窗体代码如下:
编程小白在线等。。
NodeInformationControl NIC;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
NIC = new NodeInformationControl();
NIC.Location = new Point(e.X-50, e.Y-50);
NIC.MouseLeave += new EventHandler (ControlsMouse_Leave );
this.Controls.Add(NIC);
}
private void ControlsMouse_Leave(object sender, EventArgs e)
{
NIC.Dispose();
this.Controls.Remove(NIC);
}