C#表單漸層實現

來源:互聯網
上載者:User
 1 //開啟程式後,表單由透明到不透明逐漸顯示出來。
2 //實現方法:
3 1. 添加一個Timer控制項(此例中命名為:fadeTimer),然後在其Tick事件中添加FadeTimer_Tick中的相關代碼即可,簡單吧,呵呵。
4 在該表單類的建構函式裡面添加如下代碼:
5 private bool showing = true;
6 public LoginForm()
7 {
8 InitializeComponent();
9
10 //表單顯示特效
11 Opacity = 0.0; //表單透明度為0
12 fadeTimer.Start(); //計時開始
13 }
14
15 2. Tick事件:添加如下控制碼:
16 private void FadeTimer_Tick(object sender, EventArgs e)
17 {
18 double d = 0.10;
19 if (showing)
20 {
21 if (Opacity + d >= 1.0)
22 {
23 Opacity = 1.0;
24 fadeTimer.Stop();
25 }
26 else
27 {
28 Opacity += d;
29 }
30 }
31 else
32 {
33 if (Opacity - d <= 0.0)
34 {
35 Opacity = 0.0;
36 fadeTimer.Stop();
37 } else
38 {
39 Opacity -= d;
40 }
41 }
42 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.