第一步:创建一个WaitForm

public partial class WaitForm : Form
{
private int count = -;
private ArrayList images = new ArrayList();
public Bitmap[] bitmap = new Bitmap[];
private int _value = ;
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 / ; Bitmap map = new Bitmap(, );
Graphics g = Graphics.FromImage(map); g.TranslateTransform( / 2.0F, / 2.0F);
g.RotateTransform(angle * _value);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
int[] a = new int[] { , , , , , , , };
for (int i = ; i <= ; i++)
{
int alpha = a[(i + j - ) % ];
Color drawColor = Color.FromArgb(alpha, _circleColor);
using (SolidBrush brush = new SolidBrush(drawColor))
{
float sizeRate = 3.5F / _circleSize;
float size = / ( * sizeRate); float diff = ( / 10.0F) - size; float x = ( / 80.0F) + diff;
float y = ( / 80.0F) + diff;
g.FillEllipse(brush,x,y, size, size);
g.RotateTransform(angle);
}
}
return map;
} public void Draw()
{
for (int j = ; j < ; j++)
{
bitmap[ - 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 = ; i < ; i++)
{
Draw(); //Bitmap map = new Bitmap((bitmap[i]), new Size(300, 300)); images.Add(bitmap[i]);
}
pictureBoxWait.Image = (Image)images[];
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 + ) % ;
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 / - ;
pictureBoxWait.Top = Height / - ;
pictureBoxWait.Width = ;
pictureBoxWait.Height = ;
})); } 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;
}

winfrom创建转圈等待窗体的更多相关文章

  1. Winfrom 实现转圈等待

    1.放弃进度条.动态进度图片等方式实现用户体验优化方式(主要是优化用户等待体验),建议使用方式? 答:对于From或者Control而言,其提供了Cursor属性设置即可. 例如: this.Curs ...

  2. C#中的“等待窗体”对话框

    这篇文章向您展示了如何在c#.net Windows窗体应用程序中创建一个等待窗体对话框.创建一个新表单,然后输入您的表单名称为frmWaitForm.接下来,将Label,Progress Bar控 ...

  3. [译]NeHe教程 - 创建一个OpenGL窗体

    原文: Setting Up An OpenGL Window 欢迎阅读我的OpenGL教程.我是一个热爱OpenGL的普通码农!我第一次听到OpenGL是在3Dfx刚发布他们给Voodoo I显卡的 ...

  4. 【C#】分享带等待窗体的任务执行器一枚

    -------------201504161039更新------------- 更新内容: IWaitForm接口删除System.Windows.Forms.DialogResult Dialog ...

  5. Devexpress 等待窗体

    加载窗体以及等待窗体 程序加载时,需要等待加载完成后在显示 窗体显示顺序 1. 给用户看的等待窗体 2. 加载完成后的主窗体 代码如下: 1. 等待窗体代码 #region using using S ...

  6. 【C#】带等待窗体的BackgroundWorker

    ---------------201504170911更新--------------- 更新内容:删除bgwUI新增的Start方法,改为通过new修饰符+可选参数的方式同时覆盖基类(Backgro ...

  7. c# winForm 等待窗体的实现

    最近在做一个项目,需要用到等待窗体,在DevExpress下面有SplashScreen控件可以使用,同时也有ProgressIndicator控件能用,但是如果没有用Dev开发的话,我们就需要自定义 ...

  8. PyQt5创建第一个窗体(正规套路)

    一.Pyqt5 创建第一个窗体 很多人写窗体程序都是直接敲代码,不使用设计器,我个人不是很赞成这种做法.使用设计器的好处是直观.维护方便,尤其开发复杂窗体的效率高. 但是每次修改ui文件后,需要重新生 ...

  9. C#关于等待窗体(转)

    c#.net 中如果想在主窗口A里点击打开新窗口B(因为要数据库操作,Bload需一小段时间)之前弹出带有滚动条等待子窗口C来提示用户没有死机,应该怎么做?我用多线程打开了c窗口,但是问题:1.C窗口 ...

随机推荐

  1. redis的快速机制与数据类型

    想一下 redis 的高并发和快速 单线程模型 - 避免了不必要的上下文切换和竞争条件(锁) Redis客户端对服务端的每次调用都经历了发送命令,执行命令,返回结果三个过程.其中执行命令阶段,由于Re ...

  2. matlab中struct创建方法

    MATLAB中struct创建方法可分为:直接创建法和struct()函数创建法 (1)直接创建: 直接定义字段,像使用一般matlab变量一样,不需要事先声明,支持动态扩充.下面创建一个Studen ...

  3. 14-vim-替换命令-01-替换

    命令 英文 功能 工作模式 r replace 替换当前字符 命令模式 R replace 进入替换模式 替换模式 R命令进入替换模式,输入新字符替换当前光标所在位置的字符,替换完成后,按下ESC可以 ...

  4. >>> print "hello" SyntaxError: Missing parentheses in call to 'print'

    错误原因说你的函数print缺省圆括号,可以知道你用的python是3.x版本3.x版本的python,print中的参数要用圆括号括起来,改成:print("hello")

  5. Joda-Time 入门

    Joda-Time 令时间和日期值变得易于管理.操作和理解.事实上,易于使用是 Joda 的主要设计目标.其他目标包括可扩展性.完整的特性集以及对多种日历系统的支持.并且 Joda 与 JDK 是百分 ...

  6. Validation Engine 表单验证

    前端开发仓库 » jQuery » jQuery Validation Engine 表单验证 jQuery Validation Engine 表单验证来源 功能强大的 jQuery 表单验证插件, ...

  7. sql中char,varchar,nvarchar的区别

    char[n] 是定长的,也就是当存储字符小于n时,他会自动补齐(补空值).优点:效率较varchar高. varchar[n]是变长且非unicode字符数据类型,n的取值在1到8000之间,该类型 ...

  8. ubuntu:beyond compare 4 This license key has been revoked 解决办法

    错误如图所示: 解决办法: (1)先用find命令找到bcompare所在位置:sudo find /home/ -name '*bcompare' ()进入 /home/whf/.config,删除 ...

  9. leetcode-160周赛-5240-串联字符串的最大长度

    题目描述: 自己的提交:O(2**n∗n∗m),m 为字符串长度 class Solution: def maxLength(self, arr: List[str]) -> int: from ...

  10. Ubuntu开放对外端口

    1.查看已经开启的端口 sudo ufw status 2.打开80端口 sudo ufw allow 80 3.防火墙开启 sudo ufw enable 4.防火墙重启 sudo ufw relo ...