进度条和数据加载
我有 C# 中的 Windows 窗体,具有带有大号的 Datagridview。来自数据库的记录和一些组合框、文本框和按钮。
因此,我使用了另一种具有进度条和后台工作程序的表单,以便主表单的数据加载不会刺激最终用户。
public partial class FirstForm : Form
{
MainForm mf;
public FirstForm()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
mf = new MainForm(); //inside constructor,code of data loading in gridview
mf.Update();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (p1.Value < p1.Maximum) //p1 name for progressbar
p1.Value++;
else
{
timer1.Enabled = false;
this.Hide();
mf.Show();
}
}
}
但是当主窗体显示时,它是空白的,2/3 秒后 datagridview 和其他控件出现。
如何解决这个问题..?
或提出其他想法来解决这个问题。
i have Windows Form in C# having Datagridview with large no. of records from database and some comboboxes,textbox and buttons.
so,i used another form having progressbar and backgroundworker so that data loading of mainform does not iritate enduser.
public partial class FirstForm : Form
{
MainForm mf;
public FirstForm()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
mf = new MainForm(); //inside constructor,code of data loading in gridview
mf.Update();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (p1.Value < p1.Maximum) //p1 name for progressbar
p1.Value++;
else
{
timer1.Enabled = false;
this.Hide();
mf.Show();
}
}
}
but when main form is displayed,it is blank and after 2/3 seconds datagridview and other controls appear.
how to solve this..?
or suggest other ideas to solve this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除 Firstform 中的代码并将我的代码写入
programs.cs
bw.RunWorkerAsync();
frm.Initiate(); // 将此方法添加到第一个表单以加载和启动
Remove your code in Firstform and write mine in
programs.cs
bw.RunWorkerAsync();
frm.Inittiate(); // Add this method to first form to loading and initiating