none
AnimateWindow Api 的调用问题 RRS feed

  • 问题

  • 开发环境 C# 2010

    窗体A 上的按钮 打开窗体B 窗体B的Load事件中调用AnimateWindow能实现效果  但是窗体B的Closing事件调用AnimateWindow 没有效果

    该方法的返回值也是true 请问是为什么

    2014年11月20日 14:15

全部回复

  • 你的Form_Closing 中的 code 是什麼?

    或你可以參考一下這連結

    http://www.dreamincode.net/forums/topic/109668-animating-a-windows-form/


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.

    2014年11月21日 2:01
  • 你好:

    你没有贴出代码,不太清楚你是如何调用这个API的,下面的这个示例代码是可以正常实现在窗体打开和关闭的时候实现动画效果的:

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                FadeForm myForm = new FadeForm();
                myForm.Show();
            }
        }
    
        public class FadeForm : Form
        {
            private bool _UseSlideAnimation;
    
            public FadeForm() : this(false) { }
    
            public FadeForm(bool useSlideAnimation)
            {
                _UseSlideAnimation = useSlideAnimation;
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                WinAPI.AnimateWindow(this.Handle, 1000, WinAPI.AW_ACTIVATE | (_UseSlideAnimation ? WinAPI.AW_HOR_POSITIVE | WinAPI.AW_SLIDE : WinAPI.AW_BLEND));
            }
    
            protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
            {
                base.OnClosing(e);
                if (e.Cancel == false)
                {
                    WinAPI.AnimateWindow(this.Handle, 1000, WinAPI.AW_HIDE | (_UseSlideAnimation ? WinAPI.AW_HOR_NEGATIVE | WinAPI.AW_SLIDE : WinAPI.AW_BLEND));
                }
            }
        }
    
    
        public class WinAPI
        {
            /// <span class="code-SummaryComment"><summary></span>
            /// Animates the window from left to right. 
            /// This flag can be used with roll or slide animation.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_HOR_POSITIVE = 0X1;
            /// <span class="code-SummaryComment"><summary></span>
            /// Animates the window from right to left. 
            /// This flag can be used with roll or slide animation.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_HOR_NEGATIVE = 0X2;
            /// <span class="code-SummaryComment"><summary></span>
            /// Animates the window from top to bottom. 
            /// This flag can be used with roll or slide animation.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_VER_POSITIVE = 0X4;
            /// <span class="code-SummaryComment"><summary></span>
            /// Animates the window from bottom to top. 
            /// This flag can be used with roll or slide animation.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_VER_NEGATIVE = 0X8;
            /// <span class="code-SummaryComment"><summary></span>
            /// Makes the window appear to collapse inward 
            /// if AW_HIDE is used or expand outward if the AW_HIDE is not used.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_CENTER = 0X10;
            /// <span class="code-SummaryComment"><summary></span>
            /// Hides the window. By default, the window is shown.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_HIDE = 0X10000;
            /// <span class="code-SummaryComment"><summary></span>
            /// Activates the window.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_ACTIVATE = 0X20000;
            /// <span class="code-SummaryComment"><summary></span>
            /// Uses slide animation. By default, roll animation is used.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_SLIDE = 0X40000;
            /// <span class="code-SummaryComment"><summary></span>
            /// Uses a fade effect. 
            /// This flag can be used only if hwnd is a top-level window.
            /// <span class="code-SummaryComment"></summary></span>
            public const int AW_BLEND = 0X80000;
            /// <span class="code-SummaryComment"><summary></span>
            /// Animates a window.
            /// <span class="code-SummaryComment"></summary></span>
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int AnimateWindow
            (IntPtr hwand, int dwTime, int dwFlags);
        }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年11月21日 2:36
    版主
  • 窗体A 按钮 Click事件 :    

    FromB B= new FormB(); B.Bounds = new Rectangle(100,100,100,100); B.ShowDialog();

    窗体A_Closing 事件

    AnimateWindow(this.Handle,500,AW_CENTER| AW_HIDE);

    窗体B_Load 事件

    AnimateWindow(this.Handle,500,AW_CENTER);
    窗体B_Closing 事件
    AnimateWindow(this.Handle,500,AW_CENTER| AW_HIDE);

    窗体A的关闭和 窗体B的加载动画都能实现

    窗体B的关闭没有效果 但是有延时 AnimateWindow的 返回值也是true

    2014年11月21日 7:33
  • 窗体A 按钮 Click事件 :    

    FromB B= new FormB(); B.Bounds = new Rectangle(100,100,100,100); B.ShowDialog();

    窗体A_Closing 事件

    AnimateWindow(this.Handle,500,AW_CENTER| AW_HIDE);

    窗体B_Load 事件

    AnimateWindow(this.Handle,500,AW_CENTER);
    窗体B_Closing 事件
    AnimateWindow(this.Handle,500,AW_CENTER| AW_HIDE);

    窗体A的关闭和 窗体B的加载动画都能实现

    窗体B的关闭没有效果 但是有延时 AnimateWindow的 返回值也是true

    2014年11月21日 7:33