c# - Using AnimateWindow() at Form_Load -


i have borderless form , use animatewindow() method create animations opening, closing, etc form. use code:

[flags] enum animatewindowflags {     aw_hor_positive = 0x0000000     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 }  [dllimport("user32.dll")] static  extern bool animatewindow(intptr hwnd, int time, animatewindowflags flags); 

when comes closing form, code seems work:

private void form1_formclosing(object sender, formclosingeventargs e) {     animatewindow(this.handle, 100, animatewindowflags.aw_blend | animatewindowflags.aw_hide); } 

however, when opening form code:

private void form1_load(object sender, eventargs e) {     animatewindow(this.handle, 100, animatewindowflags.aw_blend); } 

nothing seems happen. after doing guesses , tests figured using animatewindow() method make form fade out works, using make form fade in doesn't (regardless of time parameter).

any ideas?

this pretty difficult correctly, there enormous amount of code involved tricky reason through. visible property, set application class startup form , show() method when create own big deal in winforms. native window creation lazy in typical .net fashion, lots , lots of stuff happens when ball gets rolling.

the animatewindow() call must injected in between time show() method called , winforms gets chance pinvoke showwindow(). latter call ruins animation effect when try in onload(), event fires late.

you can try code, paste form class:

    protected override void setvisiblecore(bool value) {         if (!this.ishandlecreated) {             nativemethods.animatewindow(this.handle, 100, animatewindowflags.aw_blend);         }         base.setvisiblecore(value);     }      protected override void onshown(eventargs e) {         this.bringtofront();         base.onshown(e);     } 

but cannot promise work in possible cases , have not tested extensively. having call bringtofront() unpleasant hack. don't try on mdi child form, not come end.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -