代码如下:
private void Form1_SizeChanged(object sender, EventArgs e) //最小化隐藏窗体
{
if (this.WindowState == FormWindowState.Minimized)//窗体状态为最小化
{
StopRectTimer.Enabled = false;
this.Visible = false;
this.notifyIcon1.Visible = true; //显示系统托盘图标
this.notifyIcon1.Text = this.Text; //设置图标显示的文本
this.ShowInTaskbar = false; //窗体在任务标中隐藏
reghotkey();
打开OToolStripMenuItem.Text = "打开(&O)";
}
}
很显然,如果打开歌词状态话的话,怎样才能最小化而不改变窗体的大小呢?我想到了重载“最小化”,但是怎么重载呢?这里给出一种重载WndProc的方案:
代码如下:
const int WM_SYSCOMMAND = 0x112;
const int SC_CLOSE = 0xF060;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam.ToInt32() == SC_MINIMIZE)
{
this.Visible = false;
return;
}
}
base.WndProc(ref m);
}
猜你喜欢