如何覆盖最小化控件?

发布于 2024-10-08 12:57:40 字数 592 浏览 13 评论 0原文

我想重写最小化控件,而不是将窗口发送到任务栏,它会执行我编写的操作。

基本上,这就是我想要的新的最小化和恢复效果:

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

我尝试在调整大小上触发一个事件来执行此操作,但没有成功

this.Resize += new EventHandler(ChangeForm);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最偏执的依靠 2024-10-15 12:57:41

取消 WinForm 最小化?


刚刚测试了这个,当最小化时,它会使表单缩短 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);
}

Cancel A WinForm Minimize?


Just tested this and it will make the form 100 pixels shorter when minimize is clicked without flicker.

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);
}
笨笨の傻瓜 2024-10-15 12:57:41

最小化命令对于用户来说具有非常明确的含义,不应该被混淆。因此,Winforms 没有相应的事件。但这不是真正的问题,您可以通过重写 WndProc() 来检测任何 Windows 消息。就像这样:

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

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. But not a real problem, you can detect any Windows message by overriding WndProc(). 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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文