在一个窗体里执行一段数据流的操作,操作时弹出一个窗体显示进度条,完毕后自动延时关闭
问题出现是在 延时的时候标签不显示
private void CreatetAttach(string filePath)
{
Form frm = new Form();
frm.Size = new System.Drawing.Size(300, _listView.SelectedItems.Count*36+60);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
frm.ShowInTaskbar = false;
frm.Show();
int y = 5;
foreach (ListViewItem item in _listView.SelectedItems)
{
Label lable1 = new Label();
lable1.Size = new System.Drawing.Size(280, 18);
lable1.Text = item.Text;
lable1.Location = new System.Drawing.Point(5, y);
lable1.TextAlign = ContentAlignment.BottomLeft;
lable1.BringToFront();
frm.Controls.Add(lable1);
ProgressBar progressBar1 = new ProgressBar();
progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
progressBar1.Location = new System.Drawing.Point(5,y+18);
progressBar1.MarqueeAnimationSpeed = 10;
progressBar1.Size = new System.Drawing.Size(280, 13);
progressBar1.Minimum = 0;
progressBar1.BringToFront();
frm.Controls.Add(progressBar1);
y=y+36;
XmlElement el = (XmlElement)_Docment.DocumentElement.SelectSingleNode("R[@fName='" + item.Text + "']");
string fileName = filePath+@"/" + item.Text;
if (File.Exists(fileName))
{
File.Delete(fileName);
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
byte[] info = Convert.FromBase64String(el.GetAttribute("fAttach"));
progressBar1.Maximum = info.Length;
progressBar1.Step = 10;
fileStream.Write(info, 0, info.Length);
while (progressBar1.Value != info.Length)
{
progressBar1.PerformStep();
}
fileStream.Close();
}
} Label lab = new Label();
lab.Size = new System.Drawing.Size(280, 23);
lab.Text = "下载文件完毕";
lab.Location = new System.Drawing.Point(5, y+8);
frm.Controls.Add(lab);
frm.TopMost = true;
System.Threading.Thread.Sleep(1000);
frm.Close(); //frm.Deactivate += new EventHandler(frm_Deactivate);
}
问题出现是在 延时的时候标签不显示
private void CreatetAttach(string filePath)
{
Form frm = new Form();
frm.Size = new System.Drawing.Size(300, _listView.SelectedItems.Count*36+60);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
frm.ShowInTaskbar = false;
frm.Show();
int y = 5;
foreach (ListViewItem item in _listView.SelectedItems)
{
Label lable1 = new Label();
lable1.Size = new System.Drawing.Size(280, 18);
lable1.Text = item.Text;
lable1.Location = new System.Drawing.Point(5, y);
lable1.TextAlign = ContentAlignment.BottomLeft;
lable1.BringToFront();
frm.Controls.Add(lable1);
ProgressBar progressBar1 = new ProgressBar();
progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
progressBar1.Location = new System.Drawing.Point(5,y+18);
progressBar1.MarqueeAnimationSpeed = 10;
progressBar1.Size = new System.Drawing.Size(280, 13);
progressBar1.Minimum = 0;
progressBar1.BringToFront();
frm.Controls.Add(progressBar1);
y=y+36;
XmlElement el = (XmlElement)_Docment.DocumentElement.SelectSingleNode("R[@fName='" + item.Text + "']");
string fileName = filePath+@"/" + item.Text;
if (File.Exists(fileName))
{
File.Delete(fileName);
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
byte[] info = Convert.FromBase64String(el.GetAttribute("fAttach"));
progressBar1.Maximum = info.Length;
progressBar1.Step = 10;
fileStream.Write(info, 0, info.Length);
while (progressBar1.Value != info.Length)
{
progressBar1.PerformStep();
}
fileStream.Close();
}
} Label lab = new Label();
lab.Size = new System.Drawing.Size(280, 23);
lab.Text = "下载文件完毕";
lab.Location = new System.Drawing.Point(5, y+8);
frm.Controls.Add(lab);
frm.TopMost = true;
System.Threading.Thread.Sleep(1000);
frm.Close(); //frm.Deactivate += new EventHandler(frm_Deactivate);
}
解决方案 »
- You can only have one <head runat="server"> control on a page
- vs2008生成安装项目报木马
- 新手提问 用ZedGraph发布时的问题
- 我想每天下午五点定时从数据库中抓出一些数据生成一份excel文件,大家有没有好的解决方法,谢谢!
- 关于WINDOWS API里面的GETWINDOWTEXT调用
- 如何在winform程序中对url中的汉字进行解码?
- 请大家帮帮忙!关于DataGrid数据绑定的问题。
- 各位兄弟,谁知道如何查询是哪个控件发来的消息?急。。。
- C#中写下的xml,可以写进Schema路径写吗?
- C# 客户端怎么循环创建Socket连接?比如说创建10个 然后进行连接
- 如何获取SqlDataAdapter.Update()方法执行后影响的数据行数
- 帮我看看这段代码,如何连mysql,谢谢
System.Threading.Thread.Sleep(1000);
语句前添加Application.DoEvents();
试试看。
frm.Close();
是在这里吗?还是之前