我想做到QQ一样自动隐藏
我在FORM的MOVELEAVE和MOVEENTER中分别写了如下代码,但是好像不能做到很好,麻烦大家帮我改一下:
private void MainForm_MouseHover(object sender, EventArgs e) {
//窗体靠左边隐藏的时候
if (this.Left == 5 - this.Width) {
while (this.Left < 0) {
this.Left++;
}
return;
}
if (this.Left == Screen.PrimaryScreen.WorkingArea.Width - 5) {
while (this.Left > Screen.PrimaryScreen.WorkingArea.Width - this.Width) {
this.Left--;
}
return;
}
if (this.Top == 5 - this.Height) {
while (this.Top < 0) {
this.Top++;
}
return;
}
}
private void MainForm_MouseLeave(object sender, EventArgs e) {
if (this.Top <= 0) {
if (this.Left <=0) {
this.Top = 0;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = 5 - this.Width;
return;
} else if (this.Left >= Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5) {
this.Top = 0;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
return;
} else {
this.Top = 5 - this.Height;
return;
}
}
if (this.Left <= 0) {
this.Top = 0;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = 5 - this.Width;
return;
}
if (this.Left >= Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5) {
this.Top = 0;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
return;
}
}