code #1
代碼如下:
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);
}