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

C#中常用窗口特效的實(shí)現(xiàn)代碼

 更新時(shí)間:2023年12月06日 09:18:31   作者:Csharp 小記  
這篇文章主要為大家詳細(xì)介紹了C#中三個(gè)常用的窗口特效的實(shí)現(xiàn),分別是淡入淡出、變大變小、緩升緩降,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

前言

說到特效,就得談"動(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)文章

最新評(píng)論