WinForm自定义Loading控件

    在VS2008下封装WinForm自定义Loading控件。

  WinForm自定义Loading控件_第1张图片WinForm自定义Loading控件_第2张图片

     AutoCircle.cs封装了旋转的圆形,直接在里面添加Label的话,计算圆形扇面的方法有点小复杂,所以在LoadingPanel.cs将AutoCircle和Label封装在一起。该控件中提供了当LoadingPanel状态变化时的事件public event RotateStateChangedHandler OnRotateStateChanged,当打开或关闭LoadingPanel时,可以用此事件来禁用/开启页面其他控件或做其他处理。

    LoadingPanel暴露了几个属性可以对AutoCircle进行外观的设置

   WinForm自定义Loading控件_第3张图片

    

 1 private delegate bool DoWorkDelegate();
2
3
4 public Form1()
5 {
6 InitializeComponent();
7
8 this.loadingPanel1.OnRotateStateChanged += new LoadingPanel.RotateStateChangedHandler(loadingPanel1_OnRotateStateChanged);
9 }
10
11 void loadingPanel1_OnRotateStateChanged()
12 {
13 this.Invoke(new Action(delegate()
14 {
15 this.lblTip.Visible = !this.lblTip.Visible;
16 this.btnAsync.Enabled = !this.btnAsync.Enabled;
17 }));
18 }
19
20 private bool DoWork()
21 {
22 System.Threading.Thread.Sleep(5000);
23 return true;
24 }
25
26 private void DoWorkCallBack(IAsyncResult ar)
27 {
28 AsyncResult result = (AsyncResult)ar;
29 DoWorkDelegate caller = (DoWorkDelegate)result.AsyncDelegate;
30 bool bResult = caller.EndInvoke(ar);
31
32 this.loadingPanel1.Stop();
33 }
34
35 private void btnAsync_Click(object sender, EventArgs e)
36 {
37 DoWorkDelegate doWorkDelegate = this.DoWork;
38 doWorkDelegate.BeginInvoke(new AsyncCallback(DoWorkCallBack), null);
39 this.loadingPanel1.Start();
40 }

    示例源码: 

    下载地址:http://files.cnblogs.com/lichence/CustomizedLoading.rar

    个人学习,仅供参考

转载于:https://www.cnblogs.com/lichence/archive/2011/08/16/2140684.html

你可能感兴趣的:(WinForm自定义Loading控件)