[英]How to override the minimize control?
I want to override the minimize control to instead of sending the window to the taskbar it would do what ever I write it to do. 我想重写最小化控件,而不是将窗口发送到任务栏,它将执行我编写的所有操作。
Basicly this is what I wanted my new minimized and restored effects to be: 基本上,这就是我想要的新的最小化和还原效果是:
private void ChangeForm(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Height = 80;
iDebug.Visible = false;
mainMenu.Visible = false;
}
else
{
this.Height = 359;
iDebug.Visible = true;
mainMenu.Visible = true;
}
}
I have tried to fire an Event on the Resize to do this but without success 我试图在“调整大小”上触发一个事件来执行此操作,但未成功
this.Resize += new EventHandler(ChangeForm);
Cancel A WinForm Minimize? 取消WinForm最小化?
Just tested this and it will make the form 100 pixels shorter when minimize is clicked without flicker. 刚刚对此进行了测试,当单击最小化而没有闪烁时,它将使表单缩短100像素。
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MINIMIZE = 0xf020;
protected override void WndProc(ref Message m) {
if (m.Msg == WM_SYSCOMMAND) {
if (m.WParam.ToInt32() == SC_MINIMIZE) {
m.Result = IntPtr.Zero;
Height -= 100;
return;
}
}
base.WndProc(ref m);
}
The Minimize command has a very well defined meaning to a user, it shouldn't be messed with. “最小化”命令对用户而言具有非常明确的含义,不应将其弄乱。 Winforms accordingly doesn't have an event for it.
因此,Winforms没有任何活动。 But not a real problem, you can detect any Windows message by overriding WndProc().
但不是真正的问题,您可以通过覆盖WndProc()来检测任何Windows消息。 Like tihs:
像这样:
private void OnMinimize() {
this.Close(); // Do your stuff
}
protected override void WndProc(ref Message m) {
// Trap WM_SYSCOMMAND, SC_MINIMIZE
if (m.Msg == 0x112 && m.WParam.ToInt32() == 0xf020) {
OnMinimize();
return; // NOTE: delete if you still want the default behavior
}
base.WndProc(ref m);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.