a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

Winform圓形環繞的Loading動畫實現代碼

2020-01-24 02:50:23
字體:
來源:轉載
供稿:網友

之前寫了一個WPF的圓形環繞的Loading動畫,現在寫一個Winform的圓形環繞的Loading動畫。

1.新建Winform項目,添加一個pictureBox控件,命名為:pictureBox;

2.引用中添加using System.Drawing.Drawing2D;

3.Form窗體命名為:Loading,cs全部代碼如下:

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Drawing.Drawing2D;

namespace Circle_ProcessBar
{
    public partial class Loading : Form
    {
        private int count = -1;
        private ArrayList images = new ArrayList();
        public Bitmap[] bitmap = new Bitmap[8];
        private int _value = 1;
        private Color _circleColor = Color.Red;
        private float _circleSize = 0.8f;

        public Loading()
        {
            InitializeComponent();      
        }

        public Color CircleColor
        {
            get { return _circleColor; }
            set
            {
                _circleColor = value;
                Invalidate();
            }
        }

        public float CircleSize
        {
            get { return _circleSize; }
            set
            {
                if (value <= 0.0F)
                    _circleSize = 0.05F;
                else
                    _circleSize = value > 4.0F ? 4.0F : value;
                Invalidate();
            }
        }

        public Bitmap DrawCircle(int j)
        {
            const float angle = 360.0F / 8; Bitmap map = new Bitmap(150, 150);
            Graphics g = Graphics.FromImage(map);

            g.TranslateTransform(Width / 2.0F, Height / 2.0F);
            g.RotateTransform(angle * _value);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            int[] a = new int[8] { 25, 50, 75, 100, 125, 150, 175, 200 };
            for (int i = 1; i <= 8; i++)
            {
                int alpha = a[(i + j - 1) % 8];
                Color drawColor = Color.FromArgb(alpha, _circleColor);
                using (SolidBrush brush = new SolidBrush(drawColor))
                {
                    float sizeRate = 3.5F / _circleSize;
                    float size = Width / (6 * sizeRate);

                    float diff = (Width / 10.0F) - size;

                    float x = (Width / 80.0F) + diff;
                    float y = (Height / 80.0F) + diff;
                    g.FillEllipse(brush, x, y, size, size);
                    g.RotateTransform(angle);
                }
            }
            return map;
        }


        public void Draw()
        {
            for (int j = 0; j < 8; j++)
            {
                bitmap[7-j] = DrawCircle(j);
            }
        }
        protected override void OnResize(EventArgs e)
        {
            SetNewSize();
            base.OnResize(e);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            SetNewSize();
            base.OnSizeChanged(e);
        }

        private void SetNewSize()
        {
            int size = Math.Max(Width, Height);
            Size = new Size(size, size);
        }

        public void set()
        {
            for (int i = 0; i < 8; i++)
            {
                Draw();

                Bitmap map = new Bitmap((bitmap[i]), new Size(120, 110));

                images.Add(map);
            }
            pictureBox.Image = (Image)images[0];
           pictureBox.Size = pictureBox.Image.Size;

        }
        private void pictureBox_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            base.Dispose();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            set();
            count = (count + 1) % 8;
            pictureBox.Image = (Image)images[count];

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            base.Dispose();
        }
    }
}


4.效果如圖:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品久久久久久久久免费丝袜 | 国产精品日产欧美久久久久 | www.色涩涩.com网站 | 日韩手机在线视频 | 成人xxx| 国产美女精品人人做人人爽 | 好大好爽快点深一点陶软 | 欧美精品区 | 黄色电影网站在线观看 | 国产一国产寡妇一级毛片 | 亚洲成人一区二区三区 | 久久综合电影 | 日韩人体在线 | av黄色在线 | 天天综合网7799精品 | 中文一区| 日韩精品播放 | 午夜在线观看视频网站 | 亚洲一区二区视频在线观看 | 亚洲天堂一区 | 国产视频网 | 国产高清精品一区二区三区 | 日韩一区电影 | 美女诱惑av| 中文字幕久久综合 | 久草视频免费看 | 日韩在线影视 | 久久亚洲春色中文字幕久久久 | 国产伦精品一区二区三区在线 | 天堂色网| 日韩精品一区二区三区中文字幕 | 台湾佬亚洲色图 | 欧美精品久久久 | 91午夜在线 | 欧美精品久久久久久久 | 欧美成人精品一区二区男人看 | 久久亚洲一区二区三区成人国产 | 久久精品黄 | 久久九九| 国产一区免费在线观看 | 青青草国产成人av片免费 |