C#中常用窗口特效的實(shí)現(xiàn)代碼
前言
說到特效,就得談"動(dòng)"這個(gè)字,在Winform中想要?jiǎng)悠饋?,大部分可以靠Timer來實(shí)現(xiàn)(你要說我靠循環(huán)也能實(shí)現(xiàn)一樣的效果,我也無話可說),但基本上也就限制在一些比較基礎(chǔ)的效果了。不過,也沒關(guān)系,誰讓這是Winform呢?
下面描述了三種窗口的效果。分別是淡入淡出、變大變小、緩升緩降。主要通過結(jié)合Timer與透明度、大小、以及位置等來實(shí)現(xiàn)。
開發(fā)環(huán)境:.NET Framework版本:4.8
開發(fā)工具:Visual Studio 2022
實(shí)現(xiàn)步驟
淡入淡出
public Form1() { InitializeComponent(); Opacity = 0; timer1.Interval = 10; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (isShow) { if (Height < height) { Height += 1; } else { timer1.Stop(); } } else { if (ClientSize.Height > 0) { Height -= 1; } else { timer1.Stop(); Close(); } } }
變大變小
public Form2() { InitializeComponent(); height = Height; Size = new Size(Width, 0); timer1.Interval = 10; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (isShow) { if (Height < height) { Height += 1; } else { timer1.Stop(); } } else { if (ClientSize.Height > 0) { Height -= 1; } else { timer1.Stop(); Close(); } } }
緩升緩降
public Form3() { InitializeComponent(); timer1.Interval = 10; } private void Form3_Load(object sender, EventArgs e) { Location = new Point(screenRect.Width - Width, screenRect.Height); timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (isShow) { if (Location.Y > screenRect.Height-Height) { Location = new Point(Location.X, Location.Y - 1); } else { timer1.Stop(); } } else { if (Location.Y < screenRect.Height ) { Location = new Point(Location.X, Location.Y + 1); } else { timer1.Stop(); Close(); } } }
實(shí)現(xiàn)效果
到此這篇關(guān)于C#中常用窗口特效的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)C#窗口特效內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
c# n個(gè)數(shù)排序?qū)崿F(xiàn)代碼
c# n個(gè)數(shù)排序?qū)崿F(xiàn)代2009-07-07Winform學(xué)生信息管理系統(tǒng)登陸窗體設(shè)計(jì)(1)
這篇文章主要為大家詳細(xì)介紹了Winform學(xué)生信息管理系統(tǒng)登陸窗體設(shè)計(jì)思路,感興趣的小伙伴們可以參考一下2016-05-05C#算法函數(shù):獲取一個(gè)字符串中的最大長度的數(shù)字
這篇文章介紹了使用C#獲取一個(gè)字符串中最大長度的數(shù)字的實(shí)例代碼,有需要的朋友可以參考一下。2016-06-06