电脑闪屏,C# 使用委托调用待待闪屏


2、等待闪屏:相对简单,没有代码。在窗体上拖了一个Lable控件
和一个PictureBox,把Lable的Text属性设置为:“数据读取中”并且改了一下字体样式,给PictureBox装载一个gif图像
3、主窗体:在主窗体上拉个网格控件(本Demo使用Developer Express的网格控件)、一个按钮:把按钮的Text属性改为
“读取”、一个BindingSource,
下面看主窗体的实现代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.Linq;
using System.Threading;
namespace devDemo
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
frmLoading loading = new frmLoading();//闪屏窗体
#region 委托
/// <summary>
/// 关闭闪屏
/// </summary>
public delegate void Closeloading();
/// <summary>
/// 绑定数据
/// </summary>
/// <param name="ls">数据列表</param>
public delegate void BindedData(List<Product> ls);
#endregion
private void FormMain_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 读取按钮点击事件
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
new Action(ReadData).BeginInvoke(new AsyncCallback(CloseLoading), null);
loading.ShowDialog();//显示loading
}
/// <summary>
/// 读取数据
/// </summary>
public void ReadData()
{
List<Product> productList = new List<Product>();
//装载模拟数据
for (int i = 0; i < 15; i++)
{
productList.Add(new Product
{
ProductID = i + 1,
Count = new Random().Next(i * 10, 3000 / (i + 1)),
Pice = System.Math.Round(new Random().NextDouble() * (i + 1) * 100, 4),
Uint = "只",
ProductName = string.Format("产品{0}", i)
});
Thread.Sleep(200);//每添加一条记录休息200毫秒
}
this.Invoke(new BindedData((pls) => {
//绑定数据
this.protuctBindingSource.DataSource = pls;
}),productList);
}
/// <summary>
/// 关闭loading
/// </summary>
/// <param name="ar"></param>
public void CloseLoading(IAsyncResult ar)
{
this.Invoke(new Closeloading(() => { loading.Close(); }));
}
}
}
至此这个Demo完成.
Tags:  刷新闪屏 电脑显示器闪屏 笔记本闪屏 不闪式3d硬屏 电脑闪屏

延伸阅读

最新评论

发表评论