在实际项目中,经常会有窗体弹出,为了不显得那么突兀,可以给加些动画过度效果,淡入淡出就是一种比较常见的动画。 1 using System; 2 using System.Windows.Forms; 3 4 namespace TestFormEffect 5 { 6 p ...
在实际项目中,经常会有窗体弹出,为了不显得那么突兀,可以给加些动画过度效果,淡入淡出就是一种比较常见的动画。
1 using System; 2 using System.Windows.Forms; 3 4 namespace TestFormEffect 5 { 6 public partial class Form1 : Form 7 { 8 private readonly Timer _timer; 9 private readonly double _inspeed;10 private readonly double _outspeed;11 12 private State _state;13 14 public const float Precision = 0.000001f;15 16 public Form1()17 {18 InitializeComponent();19 _timer=new Timer();20 _timer.Tick += timer1_Tick; 21 _timer.Enabled = false;22 23 _inspeed = 20;24 _outspeed = 20;25 }26 27 private void Form1_Load(object sender, EventArgs e)28 {29 _state = State.In;30 _timer.Enabled = true;31 Opacity = 0;32 }33 34 private void timer1_Tick(object sender, EventArgs e)35 {36 switch (_state)37 {38 case State.In:39 Opacity += _inspeed/100;40 if (1 - Opacity <= Precision)41 {42 _timer.Enabled = false;43 }44 break;45 case State.Out:46 Opacity -= _outspeed/100;47 if (Opacity <= Precision)48 {49 this.Close();50 _timer.Enabled = false;51 }52 break;53 }54 }55 56 private void Form1_FormClosing(object sender, FormClosingEventArgs e)57 {58 e.Cancel = true;59 _state = State.Out;60 _timer.Enabled = true;61 }62 63 }64 65 enum State66 {67 In=1,68 Out69 }70 }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:炫彩效果——窗体淡入淡出
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。