Winform圓形環(huán)繞的Loading動(dòng)畫實(shí)現(xiàn)代碼
之前寫了一個(gè)WPF的圓形環(huán)繞的Loading動(dòng)畫,現(xiàn)在寫一個(gè)Winform的圓形環(huán)繞的Loading動(dòng)畫。
1.新建Winform項(xiàng)目,添加一個(gè)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.效果如圖:
- iOS動(dòng)畫教你編寫Slack的Loading動(dòng)畫進(jìn)階篇
- 一步步教你寫Slack的Loading動(dòng)畫
- Android自定義加載loading view動(dòng)畫組件
- Android實(shí)現(xiàn)創(chuàng)意LoadingView動(dòng)畫效果
- 一看就喜歡的loading動(dòng)畫效果Android分析實(shí)現(xiàn)
- jQuery實(shí)現(xiàn)彩帶延伸效果的網(wǎng)頁加載條loading動(dòng)畫
- 三款A(yù)ndroid炫酷Loading動(dòng)畫組件推薦
- javascript制作loading動(dòng)畫效果 loading效果
- javascript 通用loading動(dòng)畫效果實(shí)例代碼
- loading動(dòng)畫特效小結(jié)
相關(guān)文章
C#自動(dòng)給文章關(guān)鍵字加鏈接實(shí)現(xiàn)代碼
這篇文章主要介紹了C#自動(dòng)給文章關(guān)鍵字加鏈接實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2013-12-12VS2017使用Git進(jìn)行源代碼管理的實(shí)現(xiàn)
這篇文章主要介紹了VS2017使用Git進(jìn)行源代碼管理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07深入理解C#索引器(一種支持參數(shù)的屬性)與屬性的對(duì)比
本篇文章是對(duì)C#索引器(一種支持參數(shù)的屬性)與屬性的對(duì)比進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06C# 動(dòng)態(tài)調(diào)用WebService的示例
這篇文章主要介紹了C# 動(dòng)態(tài)調(diào)用WebService的示例,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-11-11C#自定義的方法實(shí)現(xiàn)堆棧類設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了如何使用C#創(chuàng)建一個(gè)帶有Push方法和Clist類的CStack類,并如何在其中添加和遍歷堆棧數(shù)據(jù),感興趣的可以了解下2024-03-03親自教你實(shí)現(xiàn)棧及C#中Stack源碼分析
大家都知道棧的實(shí)現(xiàn)方式有兩種,一種是基于數(shù)組實(shí)現(xiàn)的順序棧,另一種是基于鏈表實(shí)現(xiàn)的鏈?zhǔn)綏!_@篇文章主要介紹了手把手教你實(shí)現(xiàn)棧以及C#中Stack源碼分析,需要的朋友可以參考下2021-09-09