我是靠谱客的博主 优秀红酒,最近开发中收集的这篇文章主要介绍winfrom创建转圈等待窗体,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

第一步:创建一个WaitForm

public partial class WaitForm : 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;
private bool disposed = false;
public WaitForm()
{
InitializeComponent();
Instance = this;
ShowInTaskbar = false;
}
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(200, 200);
Graphics g = Graphics.FromImage(map);
g.TranslateTransform(300 / 2.0F, 300 / 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 = 300 / (6 * sizeRate);
float diff = (300 / 10.0F) - size;
float x = (300 / 80.0F) + diff;
float y = (300 / 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(300, 300));

images.Add(bitmap[i]);
}
pictureBoxWait.Image = (Image)images[0];
pictureBoxWait.Size = pictureBoxWait.Image.Size;
}
private void pictureBox_Click(object sender, EventArgs e)
{
this.Visible = false;
base.Dispose();
}
private void Timer_Tick(object sender, EventArgs e)
{
Invoke(new Action(() =>
{
foreach (Bitmap item in bitmap)
{
if (item != null)
{
item.Dispose();
}
}
images.Clear();
set();
count = (count + 1) % 8;
pictureBoxWait.Image = (Image)images[count];
}));
}
public
void ShowForm()
{
Invoke(new Action(() =>
{
Activate();
Show();
}));
}
public void StopWait()
{
Invoke(new Action(() => { Hide(); }));
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
base.Dispose();
}
public static WaitForm Instance = null;
private void WaitForm_Load(object sender, EventArgs e)
{
Invoke(new Action(() =>
{
pictureBoxWait.Left = Width / 2 - 150;
pictureBoxWait.Top = Height / 2 - 150;
pictureBoxWait.Width = 300;
pictureBoxWait.Height = 300;
}));
}
private void WaitForm_KeyDown(object sender, KeyEventArgs e)
{
Invoke(new Action(() =>
{
if (e.KeyCode == Keys.T)
{
this.Close();
}
}));
}
}

第二步:使用方法

在MainForm 初始化地方开启线程调用

tdWait = new Thread(() => { Application.Run(new WaitForm()); });
tdWait.IsBackground = true;
tdWait.Start();

第三步:在需要使用的地方使用

WaitForm.Instance.ShowForm();
AppointModels appModels = new AppointModels();
ResultModels result = HISManager.DownloadAppointData(JsonConvert.SerializeObject(appModels));
WaitForm.Instance.StopWait();

第四步:在MainForm Close 的地方关闭线程

 if (tdWait != null)
{
tdWait.Abort();
tdWait = null;
}

 

转载于:https://www.cnblogs.com/techdreaming/p/10875313.html

最后

以上就是优秀红酒为你收集整理的winfrom创建转圈等待窗体的全部内容,希望文章能够帮你解决winfrom创建转圈等待窗体所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部