当前位置: 移动技术网 > IT编程>开发语言>c# > c# 重载WndProc,实现重写“最小化”的实现方法

c# 重载WndProc,实现重写“最小化”的实现方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
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);
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网