欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)winform漸變效果的方法

 更新時間:2014年10月16日 10:43:32   投稿:shichen2014  
這篇文章主要介紹了C#實現(xiàn)winform漸變效果的方法,涉及到窗體的設(shè)計與屬性的修改等技巧,需要的朋友可以參考下

本文實例實現(xiàn)一個啟動畫面,采用了顯示Aform,過一段時間,隱藏這個Aform,showdialog下一個Bform,closeAForm這個方法來做了,不知道大家有沒有更好的辦法。
設(shè)定程序從Aform啟動:

復(fù)制代碼 代碼如下:
static void Main() 

  Application.EnableVisualStyles(); 
  Application.SetCompatibleTextRenderingDefault(false); 
  Application.Run(new Aform()); 
}

AForm中定義如下timer:

StartWindowShowTime    HideWindowStart    HideWindowSpeed   ShowWindowStart

定義了他們的屬性:

StartWindowShowTime(顯示Aform的時間長度) Enabled=True Interval=5000 (100=1秒)
HideWindowStart (開始隱藏Aform的過程) Enabled=True Interval=4500
HideWindowSpeed (隱藏Aform的漸變間隔) Enabled=False Interval=10
ShowWindowStart  (顯示AForm的漸變間隔) Enabled=True Interval=10

下面開始定義這些timer的Tick 在Events里面可以直接填寫,timer就這一個,也可以后臺寫,不過我覺得在這里填寫比較方便,而且可以自動生成方法的聲明,不用找了。偷懶一下。

StartWindowShowTime Tick:ShowMainwindow
HideWindowStart  Tick:HideWindow
HideWindowSpeed  Tick:HideWindowSpeedStart
ShowWindowStart Tick:ShowWindow

好了,到這里我要說Windows Form 實現(xiàn)透明效果,漸變效果,淡入淡出效果的實現(xiàn)最重要一員了,那就是Form屬性里的Opacity,用的就是這個。我考證過,只有2000以上的系統(tǒng)支持這個屬性。

我們先將Aform的Opacity設(shè)置成0,好了開始寫Aform的代碼

復(fù)制代碼 代碼如下:
public partial class Aform: Form 

       public Form() 
       { 
           InitializeComponent();  
       } 
 
       private void Start_Load(object sender, EventArgs e) 
       { 
           StartWindowShowTime.Start(); 
           HideWindowStart.Start(); 
       } 
 
       private void ShowMainwindow(object sender, EventArgs e) 
       { 
           Bform showmainwindows = new Bform();             
           this.Hide(); 
           StartWindowShowTime.Stop(); 
           HideWindowStart.Stop(); 
           HideWindowSpeed.Stop(); 
           showmainwindows.ShowDialog(); 
           this.Close(); 
       } 
 
       private void HideWindow(object sender, EventArgs e) 
       { 
           HideWindowSpeed.Start(); 
       } 
 
       private void HideWindowSpeedStart(object sender, EventArgs e) 
       { 
           this.Opacity = this.Opacity - 0.02; 
       } 
 
       private void ShowWindow(object sender, EventArgs e) 
       { 
           if (this.Opacity == 1) 
           { 
               ShowWindowStart.Stop(); 
           } 
           else 
           { 
               this.Opacity = this.Opacity + 0.02; 
           } 
       } 
}

好了,這個時候大家運行看看,可以看到有淡入淡出效果。
我本來把Opacity每次更改的數(shù)值設(shè)置成了0.1,可是發(fā)現(xiàn)如果那樣的話淡入淡出不是很潤,所以縮小了數(shù)值和間隔時間。這樣看起來就潤多了。自我感覺不錯。
如果大家的程序只需要透明,那么只用設(shè)置Opacity這個就可以了。

漸變和淡入淡出照貓畫虎用timer和Opacity這個配合一下,就可以做出來了。

希望本文所述對大家的C#程序設(shè)計有所幫助

相關(guān)文章

最新評論