C#中常用窗口特效的實現(xiàn)代碼
前言
說到特效,就得談"動"這個字,在Winform中想要動起來,大部分可以靠Timer來實現(xiàn)(你要說我靠循環(huán)也能實現(xiàn)一樣的效果,我也無話可說),但基本上也就限制在一些比較基礎(chǔ)的效果了。不過,也沒關(guān)系,誰讓這是Winform呢?
下面描述了三種窗口的效果。分別是淡入淡出、變大變小、緩升緩降。主要通過結(jié)合Timer與透明度、大小、以及位置等來實現(xiàn)。
開發(fā)環(huán)境:.NET Framework版本:4.8
開發(fā)工具:Visual Studio 2022
實現(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();
}
}
}實現(xiàn)效果

到此這篇關(guān)于C#中常用窗口特效的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)C#窗口特效內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#基礎(chǔ)語法:結(jié)構(gòu)和類區(qū)別詳解
這篇文章主要介紹了C#基礎(chǔ)語法:結(jié)構(gòu)和類詳解,本文總結(jié)了一些結(jié)構(gòu)和類的不同之處并給出了測試區(qū)別特性代碼,需要的朋友可以參考下2015-06-06
基于C#實現(xiàn)JPG轉(zhuǎn)PDF的具體方案
在當今數(shù)字化時代,文檔處理已成為日常工作和生活中不可或缺的一部分,為了適應各種場景的需求,文檔格式之間的轉(zhuǎn)換顯得尤為重要,PDF和JPG格式之間的轉(zhuǎn)換是常見的需求之一,本文給大家介紹了基于C#實現(xiàn)JPG轉(zhuǎn)PDF的具體方案,需要的朋友可以參考下2025-09-09

