代码实现的是类似QQ那种拖到边界会自动隐藏的效果,开始的时候就可以,但是
第一个问题::当我点击缩小按钮后,,,再次双击托盘(notifyIcon1)显示窗体时,就无法再次实现QQ自动隐藏效果。请问下,怎么解决此问题第二个问题::怎么让窗体再次显示时是在屏幕中间??我加上(this.WindowState=FormWindowState.Normal)没效果,,还是显示在屏幕的左上角。。 //窗体隐藏效果 int form_MODE = 0,
form_T = 3,
form_XY = 6;
private void form_hide_Tick(object sender, EventArgs e)
{
if (MouseButtons == MouseButtons.Left)
return; int x = MousePosition.X, y = MousePosition.Y; if (x > (this.Location.X - form_XY)
&&
x < (this.Location.X + this.Width + form_XY)
&&
y > (this.Location.Y - form_XY)
&&
y < (this.Location.Y + this.Height + form_XY))
{
if (this.form_MODE == 1)
this.Location = new Point(form_T, this.Location.Y);
else if (this.form_MODE == 2)
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - form_T, this.Location.Y);
else if (this.form_MODE == 3)
this.Location = new Point(this.Location.X, form_T);
} else//鼠标移动到窗口外,隐藏
{
if (this.Location.Y <= form_T)//上
{
this.Location = new Point(this.Location.X, form_T - this.Height);
this.form_MODE = 3;
}
else if (this.Location.X <= form_T)//左
{
this.Location = new Point(form_T - this.Width, this.Location.Y);
this.form_MODE = 1;
}
else if (this.Location.X >= Screen.PrimaryScreen.WorkingArea.Width - this.Width - form_T)//右
{
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form_T, this.Location.Y);
this.form_MODE = 2;
}
else
this.form_MODE = 0;
} } private void main_Move(object sender, EventArgs e)
{
this.form_MODE = 0;
} private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == false)
{
this.WindowState = FormWindowState.Maximized;
this.Visible = true;
this.Activate(); }
else
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}
} private void main_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
}
第一个问题::当我点击缩小按钮后,,,再次双击托盘(notifyIcon1)显示窗体时,就无法再次实现QQ自动隐藏效果。请问下,怎么解决此问题第二个问题::怎么让窗体再次显示时是在屏幕中间??我加上(this.WindowState=FormWindowState.Normal)没效果,,还是显示在屏幕的左上角。。 //窗体隐藏效果 int form_MODE = 0,
form_T = 3,
form_XY = 6;
private void form_hide_Tick(object sender, EventArgs e)
{
if (MouseButtons == MouseButtons.Left)
return; int x = MousePosition.X, y = MousePosition.Y; if (x > (this.Location.X - form_XY)
&&
x < (this.Location.X + this.Width + form_XY)
&&
y > (this.Location.Y - form_XY)
&&
y < (this.Location.Y + this.Height + form_XY))
{
if (this.form_MODE == 1)
this.Location = new Point(form_T, this.Location.Y);
else if (this.form_MODE == 2)
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - form_T, this.Location.Y);
else if (this.form_MODE == 3)
this.Location = new Point(this.Location.X, form_T);
} else//鼠标移动到窗口外,隐藏
{
if (this.Location.Y <= form_T)//上
{
this.Location = new Point(this.Location.X, form_T - this.Height);
this.form_MODE = 3;
}
else if (this.Location.X <= form_T)//左
{
this.Location = new Point(form_T - this.Width, this.Location.Y);
this.form_MODE = 1;
}
else if (this.Location.X >= Screen.PrimaryScreen.WorkingArea.Width - this.Width - form_T)//右
{
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form_T, this.Location.Y);
this.form_MODE = 2;
}
else
this.form_MODE = 0;
} } private void main_Move(object sender, EventArgs e)
{
this.form_MODE = 0;
} private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == false)
{
this.WindowState = FormWindowState.Maximized;
this.Visible = true;
this.Activate(); }
else
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}
} private void main_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
}
private FormWindowState _oldStatus=FormWindowState.Minimized;
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == false)
{
this.WindowState = _oldStatus;
this.Visible = true;
this.Activate();
}
else
{
_oldStatus=this.WindowState;
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}
} 这样试试看
你下面的语句 只是把窗体的状态设为普通状态 、并没有位置的部分。
this.WindowState=FormWindowState.Normal