C#winform自動中央、および特効

7266 ワード

 using System.Runtime.InteropServices;
 public class Win32
 {
  public const Int32 AW_HOR_POSITIVE = 0x00000001; //  
  public const Int32 AW_HOR_NEGATIVE = 0x00000002; //  
  public const Int32 AW_VER_POSITIVE = 0x00000004; //  
  public const Int32 AW_VER_NEGATIVE = 0x00000008; //  
  public const Int32 AW_CENTER = 0x00000010; // AW_HIDE , ; AW_HIDE , 。
  public const Int32 AW_HIDE = 0x00010000; // , 。
  public const Int32 AW_ACTIVATE = 0x00020000; // 。 AW_HIDE 。
  public const Int32 AW_SLIDE = 0x00040000; // 。 。 AW_CENTER , 。
  public const Int32 AW_BLEND = 0x00080000; // 。 hWnd 。
  [DllImport("user32.dll", CharSet = CharSet.Auto)]
  public static extern bool AnimateWindow(
    IntPtr hwnd, // handle to window
    int dwTime, // duration of animation
    int dwFlags // animation type
    );
 }
 /**//* */
 private void Form_Load(object sender, EventArgs e)
 {
  Win32.AnimateWindow(this.Handle, 2000, Win32.AW_BLEND);
 }
 /**//* */
 private void Form_FormClosing(object sender, FormClosingEventArgs e)
 {
  Win32.AnimateWindow(this.Handle, 2000, Win32.AW_SLIDE | Win32.AW_HIDE | Win32.AW_BLEND);
 }

2、フォームが中央にあるCode


      /**//// <summary>
        ///  
        /// </summary>
        public static void SetMid(Form form)
        {
            // Center the Form on the user's screen everytime it requires a Layout.
            form.SetBounds((Screen.GetBounds(form).Width / 2) - (form.Width / 2),
                (Screen.GetBounds(form).Height / 2) - (form.Height / 2),
                form.Width, form.Height, BoundsSpecified.Location);
        }