点击“X”或“Alt+F4”时,最小化窗口 点击“X”或“Alt+F4”时,最小化窗口,不是关闭窗口. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected override void WndProc(ref Message m) { if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060)) base.WndProc(ref m); else this.Hide(); } //也许不是最好1)使用HOOK(钩子函数)监测键盘输入;2)符合条件则将窗体最小化(类似于托盘); 处理FormClosing事件:e.Cancel=true;this.WindowState=FormWindowState.Minimized; if (e.KeyCode == Keys.X || (e.KeyCode == Keys.F4 && e.KeyCode == Keys.Alt)) { this.WindowState = FormWindowState.Minimized; } protected override void guan(ref Message m) { if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060)) base.guan(ref m); else this.Hide(); } if (e.KeyCode == Keys.X || (e.KeyCode == Keys.F4 && e.KeyCode == Keys.Alt)) { this.WindowState = FormWindowState.Minimized; } protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; const int SC_MINIMIZE = 0xF020; if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE)) { //最小化到系统栏 this.Hide(); return; } base.WndProc(ref m); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; }这种倒是可以,就是它还在任务栏里面,怎么才可以到系统托盘中呢 使用notifyIcon控件可以显示到系统托盘中 也可以重载dispose方法,因为close方法是调用了dispose方法的 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason ==CloseReason.UserClosing) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; } } private void button1_Click(object sender, EventArgs e) { this.Dispose(); } FormClosing结合notifyIcon即可实现了。 C#winform 弹出自定义对话框? select返回多个值,用C#如何取得其中一个的值? 内部链接(字符串替换) 请教:关于字段初始化的问题 menuStrip 制作菜单的时候文字与图片不对齐的问题 连不上数据库sql2005 谁会用NextInstaller打包控制台应用程序 C#打印ACCESS程序已经链接好的access数据库对应的表 UML问题 进程间通信,使用WM_COPYDATA消息在两个程序间传递字符串,有问题。 把登陆名字段username改为userid 后出现的奇怪问题 ,请前辈们指教! 我在pictureBox1写字后,如何保存为图片?
protected override void WndProc(ref Message m)
{
if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060)) base.WndProc(ref m);
else this.Hide();
}
1)使用HOOK(钩子函数)监测键盘输入;
2)符合条件则将窗体最小化(类似于托盘);
this.WindowState=FormWindowState.Minimized;
{
this.WindowState = FormWindowState.Minimized;
}
{
if (!(m.Msg == 0x112 && m.WParam.ToInt32() == 0xF060))
base.guan(ref m);
else this.Hide();
}
{
this.WindowState = FormWindowState.Minimized;
}
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
const int SC_MINIMIZE = 0xF020; if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE))
{
//最小化到系统栏
this.Hide();
return;
}
base.WndProc(ref m);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
这种倒是可以,就是它还在任务栏里面,怎么才可以到系统托盘中呢
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason ==CloseReason.UserClosing)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
} } private void button1_Click(object sender, EventArgs e)
{
this.Dispose();
}