日期:2014-05-18 浏览次数:21113 次
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0112: // WM_SYSCOMMAND
{
if (m.WParam.ToInt32() == 0xF020) // SC_MINIMIZE
{
if (m.LParam.ToInt32() > 0)
{
// 点击的
}
}
break;
}
default:
break;
}
base.WndProc(ref m);
}
------解决方案--------------------
接3楼,if (m.LParam.ToInt32() > 0) 成立是点击的最小化按钮,不成立是点的任务栏
------解决方案--------------------
我觉得你的最小化到托盘可以这样写:
1 拉一个NotifyIcon控件notifyIcon,为控件notifyIcon的属性Icon添加一个icon图标。
2 private void frmMain_SizeChanged(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon1.Visible=true;
}
}
3 为notifyIcon1添加双击事件
private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
4 也可以再给notifyIcon添加右键菜单
------解决方案--------------------
加 return
if (m.LParam.ToInt32() > 0)
{
this.Hide();
return;
}
------解决方案--------------------