时间:2021-05-20
之前写了一个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.效果如图:
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Winform动态加载TabControl用法。分享给大家供大家参考。具体实现代码如下:复制代码代码如下:privatevoidBindTabDa
本文实例为大家分享了JS实现网页加载中效果的具体代码,供大家参考,具体内容如下需要材料:一张loading动画的gif图片基本逻辑:模态框遮罩+loading.
本文以一个非常简单的实例讲述了Winform实现抓取web页面内容的方法,代码简洁易懂,非常实用!分享给大家供大家参考。具体实现代码如下:WebRequestr
本文实例为大家分享了H5canvas投篮小游戏实现代码,供大家参考,具体内容如下loading......varbackLayer,cLayer,enemy,g
本文实例为大家分享了winform编辑器的具体实现代码,供大家参考,具体内容如下usingSystem;usingSystem.Collections.Gene