找到你要的答案

Q:Change Minimizing Visual Effect

Q:改变视觉效果最小化

I've created an app with invisible form. (Opacity = 0 or Visible = false ShowInTaskbar = false) I've tried a lot of different ways of activating my form while having active other applications. By "activating" I mean giving focus to it without making it visible. For some reason, Activate() and Focus() methods are not working as supposed. According to MSDN (https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) Activate() method should cause focus of window if form is not minimized, but it is not working.

The only way I found to activate (focus) my window is minimize it and then return its state to Normal. It is working just perfect, but there is another problem: for Windows XP it causes constant effect of minimizing and maximizing of window, even though it is invisible. Is there a way to make this effect not visible just for my form?

Right now this effect is looking like this:

I've created an app with invisible form. (Opacity = 0 or Visible = false ShowInTaskbar = false) I've tried a lot of different ways of activating my form while having active other applications. By "activating" I mean giving focus to it without making it visible. For some reason, Activate() and Focus() methods are not working as supposed. According to MSDN (https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) Activate() method should cause focus of window if form is not minimized, but it is not working.

我发现激活窗口的唯一方法是最小化它,然后将它的状态返回到正常状态。它的工作就是完美,但是还有一个问题:Windows XP造成的最小化和最大化窗口的持续作用,即使它是无形的。有没有办法让这种效果不为我的身体所见?

现在这个效果看起来像这样:

answer1: 回答1:

According to exact the complementary problem I had (I wanted to have those effects, but they didn't work), I think this could solve you problem:

What about changing your forms BorderStyle to none? Before minimiting call this:

this.FormBorderStyle = FormBorderStyle.None;

After maximizing that:

this.FormBorderStyle = FormBorderStyle.FixedSingle;

This resolves the winform to neither have a minimize nor maximize nor restore nor aerial effect.

Thus it might solve the wrong minimize/maximize effects.

根据确切的补充问题,我有(我想有这些影响,但他们没有工作),我认为这可以解决你的问题:

What about changing your forms BorderStyle to none? Before minimiting call this:

this.FormBorderStyle = FormBorderStyle.None;

最大化后:

this.FormBorderStyle = FormBorderStyle.FixedSingle;

这解决了WinForm中都没有减少或最大限度地恢复和天线效应也不。

因此,它可能会解决错误最小化/最大化的影响。

answer2: 回答2:

Ok, I managed to find answer to my question, very similar question has already been on Stack Overflow, my fault: Is it possible to disable animation when minimizing / restoring window?

To be short, you just need to catch minimization system message in following way:

protected override void WndProc(ref Message m) {
        // Catch WM_SYSCOMMAND, SC_MINIMIZE
        if (m.Msg == 0x112 && m.WParam.ToInt32() == 0xf020) {
            this.Hide();
            this.WindowState = FormWindowState.Minimized;
            this.BeginInvoke(new Action(() => this.Show()));
            return;
        }
        base.WndProc(ref m);
    }

好吧,我设法找到我的问题的答案,非常类似的问题已经在堆栈溢出,我的错误:是否有可能禁用动画时,最大限度地减少/恢复窗口?

总之,你只需要以以下方式捕捉最小化系统消息:

protected override void WndProc(ref Message m) {
        // Catch WM_SYSCOMMAND, SC_MINIMIZE
        if (m.Msg == 0x112 && m.WParam.ToInt32() == 0xf020) {
            this.Hide();
            this.WindowState = FormWindowState.Minimized;
            this.BeginInvoke(new Action(() => this.Show()));
            return;
        }
        base.WndProc(ref m);
    }
c#  .net  forms  windows-xp  effects