简体   繁体   中英

Skip Aero Window Animation

How can I disable the "opening" animation of a window under Aero programatically?

When opening a new Form it "pops in" (fade in + a slight scaling transformation). I want to stop this animation and show the window instantly.

I already tried to set the Location property of the Form to somewhere offscreen, then calling Show(), and then moving it at its correct location. But that doesn't help, the animation will continue.

Maybe there is some hidden property I can set?

I don't want to disable open/close/minimize/maximize animations globally! I just want to skip the "window-open" animation of my window.

I already played around with single and multiple calls ShowWindow(...) directly after Form.Show(). But no matter what parameters I pass, doesn't abort the opening-animation.

I've got it! After some trying around with ShowWindow, BorderStyles I found my exact solution:

  1. Change the initial "FormBorderStyle" property of the form to one of those:
    • None
    • FixedToolWindow
    • SizeableToolWindow
  2. Add a eventhandler to the Forms "Shown" event.
  3. Inside the eventhandler, change the FormBorderStyle to "Sizeable" (or any other).

Now the trick is that "none" and "*toolwindow" borderstyles will suppress the opening/popup animation for that form. Than, as soon as the form is being displayed the borderstyle is changed, giving it the original functionality (Icon in the Control-Bar, Minimize/Maximize Buttons etc...)

Edit : For everyone who might want to try this too, I have to point out that thiscanwill screw with the actual size of the window when done with PInvoke commands. If you rely on the size of the window being correct, be sure to resize the the window to its intended size after you done this.

这是 Windows 视觉效果的一部分,可以使用SystemParametersInfo方法进行调整。

I found that the animation is only take place when the form is shown for the first time.

So here is the trick:

var form = new Form();
form.Show();
form.Hide();
form.Show();

I tested it only in Windows 8

You can change the style before and after, like this, which will prevent the fade-out animation.

        this.FormBorderStyle = FormBorderStyle.Sizable;
        this.Show();

        // Do whatever

        this.FormBorderStyle = FormBorderStyle.Sizable;
        this.Show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM