AnimateWindow have no effect on maximazed form c#

1

I'm trying to animate the form on loading. I used AnimateWindow:

 public partial class AdministrationMDI : Form
{
    [DllImport("user32")]
    static extern bool AnimateWindow(IntPtr hwnd, int time, AnimateWindowFlags flags);

    public AdministrationMDI()
    {

        InitializeComponent();

    }
    enum AnimateWindowFlags : uint
    {
        AW_HOR_POSITIVE = 0x00000001,
        AW_HOR_NEGATIVE = 0x00000002,
        AW_VER_POSITIVE = 0x00000004,
        AW_VER_NEGATIVE = 0x00000008,
        AW_CENTER = 0x00000010,
        AW_HIDE = 0x00010000,
        AW_ACTIVATE = 0x00020000,
        AW_SLIDE = 0x00040000,
        AW_BLEND = 0x00080000
    }

And i call it on form_load:

private void AdministrationMDI_Load(object sender, EventArgs e)
    {

        AnimateWindow(this.Handle, 1000, AnimateWindowFlags.AW_BLEND);

    }

but when i put windowstate property on 'maximized' , the animation doesn't work. Is there any solution to resolve this ? Thank you!

c#
animatewindow
asked on Stack Overflow Mar 16, 2016 by Ahmed Fantar

1 Answer

0
protected override void OnLoad(EventArgs e)
{
    this.Visible = false;
    this.Opacity = 1;
    AnimateWindow(this.Handle, 1000, AnimateWindowFlags.AW_BLEND);
    base.OnLoad(e);
}

You can try this code, paste it into your Form class. It works in the project that I'm working on.I hope that these help to you.

answered on Stack Overflow May 3, 2017 by M.min • edited May 3, 2017 by Tom

User contributions licensed under CC BY-SA 3.0