動畫啓動窗口的類(源碼)

這個類相當的簡單,所以我只把源碼完整的貼了出來.

必要的地方,我會作相應說明.

==============================================================


 * 說明:
 *
 *  1.命名空間: Apc_AniWindow
 *    類名    : AniWindow
 *
 *   2.聲明: AniWindow a=new AniWindow(this.Handle,100,1,this);
 *
 *  3.參數說明:AniWindow(窗口句柄,動畫樣式,打開或關閉標誌,實例表單);
 *    窗口句柄: this.Handle
 *    動畫樣式: 0  -> 普通顯示
 *     1  -> 從左向右顯示
 *      2  -> 從右向左顯示
 *      3  -> 從上到下顯示
 *      4  -> 從下到上顯示
 *      5  -> 透明漸變顯示
 *      6  -> 從中間向四周
 *      7  -> 左上角伸展
 *      8  -> 左下角伸展
 *      9  -> 右上角伸展
 *      10 -> 右下角伸展
 *    開關標誌: 0爲關閉窗口 1爲打開窗口
 *    實例表單: 爲了去除Label的BUG, 取值 this
 *
 * ===============================================================
 *
 * 另有不得不說的BUG,目前我只知當FORM上有可視的Label的時候,會出錯,現已解決.
 * 但不知道還有沒有別的控件會引發錯誤,
 *
 * 還有,如果是Form上的Label,程序會自動設爲不可視,如果是Panel裏面的....X_X 還是會出錯.
 * 所以,如果你的程序裏有LABEL,還是在PANEL中,,,那你只好自己寫代碼來實現可視不可視嘍...
 *
 ******************************************************************/
using System;
using System.Windows.Forms;
namespace Apc_AniWindow
{
 /// <summary>
 /// Class1 的摘要說明。
 /// </summary>
 public class AniWindow
 {
  [System.Runtime.InteropServices.DllImport("user32")]
  private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
  private const int AW_HOR_POSITIVE = 0x0001;
  private const int AW_HOR_NEGATIVE = 0x0002;
  private const int AW_VER_POSITIVE = 0x0004;
  private const int AW_VER_NEGATIVE = 0x0008;
  private const int AW_CENTER = 0x0010;
  private const int AW_HIDE = 0x10000;
  private const int AW_ACTIVATE = 0x20000;
  private const int AW_SLIDE = 0x40000;
  private const int AW_BLEND = 0x80000;
  private int CloseOpen=0x20000;

  public AniWindow(IntPtr hwnd,int dwFlags,int CloseOrOpen,System.Windows.Forms.Form myform)
  {
   try
   {
    if(CloseOrOpen==1)
    {
     foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
     {
      string m=mycontrol.GetType().ToString();
      m=m.Substring(m.Length-5);
      if(m=="Label")
      {
       mycontrol.Visible=false;     //這裏是在動畫效果之前,把表單上可視的LABEL設爲不可視
      }
     }
    }
    //打開or關閉 0是關閉  1是打開
    if(CloseOrOpen==0){CloseOpen=0x10000;}
    if(dwFlags==100)
    {
     int zz=10;
     Random a=new Random();
     dwFlags=(int)a.Next(zz);
    }

   
    switch(dwFlags)
    {
     case 0://普通顯示
      AnimateWindow(hwnd,200,AW_ACTIVATE);
      break;
     case 1://從左向右顯示
      AnimateWindow(hwnd,200,AW_HOR_POSITIVE|CloseOpen);
      break;
     case 2://從右向左顯示
      AnimateWindow(hwnd,200,AW_HOR_NEGATIVE|CloseOpen);
      break;
     case 3://從上到下顯示
      AnimateWindow(hwnd,200,AW_VER_POSITIVE|CloseOpen);
      break;
     case 4://從下到上顯示
      AnimateWindow(hwnd,200,AW_VER_NEGATIVE|CloseOpen);
      break;
     case 5://透明漸變顯示
      AnimateWindow(hwnd,200,AW_BLEND|CloseOpen);
      break;
     case 6://從中間向四周
      AnimateWindow(hwnd,200,AW_CENTER|CloseOpen);
      break;
     case 7://左上角伸展
      AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_POSITIVE|CloseOpen);
      break;
     case 8://左下角伸展
      AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_NEGATIVE|CloseOpen);
      break;
     case 9://右上角伸展
      AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_POSITIVE|CloseOpen);
      break;
     case 10://右下角伸展
      AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_NEGATIVE|CloseOpen);
      break;
    }
    if(CloseOrOpen==1)
    {
     foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
     {
      string m=mycontrol.GetType().ToString();
      m=m.Substring(m.Length-5);
      if(m=="Label")
      {
       mycontrol.Visible=true;  //這裏恢復LABEL的可視.
      }
     }
    }
   }
   catch{}
  }
 }

}

把這代碼,貼到.NET環境中, 直接編譯就可以了.

或者直接放在代碼中,用就可以了.

歡迎交流.

另外,我用  form的  region屬性,也做了一個,普通的動畫例子,但是沒有API的效果好,(但是絕對沒有BUG,比如label這樣的錯)

但可惜的是,一指定 form的 region , 當窗體改變大小時, 還要重新設置一下, region

哎.....不知道有什麼好的辦法..更好的辦法.....

發佈了38 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章