C# AnimateWindow与WindowState同时使用的效果

在使用窗体动画显示的效果时,用到了以下代码:

[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

 AnimateWindow(this.Handle, 500, AW_BLEND);

当窗体的WindowState属性被设置时,如设置为最大化

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

这时候使用AnimateWindow()函数,就会让本应该最大化的窗体无法覆盖任务栏而达不到最大化效果;

解决方法:

      在使用该函数前,设置窗体大小,而不是设置WindowState,设置窗体为屏幕大小

int x = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width;
int y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height;
this.Size = new Size(1024, 768);//设置窗体大小;
this.Location = new Point(0, 0);//设置窗体位置;

调用这段代码后,再使用函数,动画显示窗体,窗体也能最大化

原文地址:https://www.cnblogs.com/yuxuan/p/1856826.html