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);
}

以上就是【c# 重载WndProc,实现重写“最小化”的实现方法】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)

与本文相关的软件

发表我的评论

最新评论

  1. 暂无评论