我有一个将excel记录导入用户界面以读取数据的应用程序。导入需要花费相当长的时间,因此我试图为用户实现进度条以查看进度。
首先,我以外部形式进行操作,并且一切正常。现在,我将其更改为加载表单上的进度条,突然不起作用。我所做的只是从班级资源表中获取表单参考。这是执行进度条的代码。
我对代码所做的唯一更改是更改为“ OpenForm”,因为这是新的进度条。我知道这段代码会将进度条设置为20,之后不会再移动。这是在只带有进度条的表单上进行的,但是在此表单上却不起作用。我想念什么吗?
OpenForm.progressBar1.Minimum = 0;
OpenForm.progressBar1.Maximum = 100;
OpenForm.progressBar1.Step = 1 / 50;
for (int row = 8; row <= 50; row++)
{
IssueRef.Add(ExcelWksht1.Cells[row, 1].Value.ToString());
Date.Add(ExcelWksht1.Cells[row, 4].Value.ToString());
Status.Add(ExcelWksht1.Cells[row, 2].Value.ToString());
Severity.Add(ExcelWksht1.Cells[row, 9].Value.ToString());
Text.Add(ExcelWksht1.Cells[row, 3].Value.ToString());
decimal ProgressVal = ( 10m /50m) * 100m;
int Val = Convert.ToInt32(ProgressVal);
OpenForm.progressBar1.Value = Val;
OpenForm.progressBar1.Refresh();
}
答案 0 :(得分:-2)
for (int row = 8; row <= 50; row++)
{
IssueRef.Add(ExcelWksht1.Cells[row, 1].Value.ToString());
Date.Add(ExcelWksht1.Cells[row, 4].Value.ToString());
Status.Add(ExcelWksht1.Cells[row, 2].Value.ToString());
Severity.Add(ExcelWksht1.Cells[row, 9].Value.ToString());
Text.Add(ExcelWksht1.Cells[row, 3].Value.ToString());
decimal ProgressVal = ( 10m /50m) * 100m;
int Val = Convert.ToInt32(ProgressVal);
OpenForm.progressBar1.Value = Val;
//OpenForm.progressBar1.Refresh(); remove this
//add
Application.DoEvents();
}