有两个窗体F1和F2,F2是下载文件用的。目的是,F2下载完成后才出现F1。F1启动F2,代码如下: private void F1_Load(object sender, EventArgs e)
{
F2 f2 = new F2();
f2.Show();
}
F2窗体里面下载文件,我用的是异步,来实现进度条效果,代码如下:private void F2_Load(object sender, EventArgs e)
{
Start_DownFile(string URL, string FileNamePath);
} //定义委托
delegate void Delegate_DownFile(string URL, string FileNamePath); //回调函数
private void CallBackMethod_DownFile(IAsyncResult ar)
{
Delegate_DownFile dn = (Delegate_DownFile)ar.AsyncState;
} //用线程方式启动
private void Start_DownFile(string URL, string FileNamePath)
{
Delegate_DownFile dn = new Delegate_DownFile(DownFile);
AsyncCallback acb = new AsyncCallback(CallBackMethod_DownFile);
IAsyncResult iar = dn.BeginInvoke(URL, FileNamePath, acb, dn); } //下载文件
private void DownFile(string URL, string FileNamePath)
{ try
{
WebClient client = new WebClient(); //下载过程中
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
//下载完成
client.DownloadFileCompleted += client_DownloadFileCompleted; Uri uri = new Uri(URL);
client.DownloadFileAsync(uri, FileNamePath);
}
catch (UriFormatException ex)
{
} } private void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
SetStatus1(e.ProgressPercentage);
}delegate void SetTextCallback1(int i); public void SetStatus1(int i)
{
if (this.Pbar.InvokeRequired)
{
SetTextCallback1 d = new SetTextCallback1(SetStatus1);
this.Invoke(d, new object[] { i });
}
else
{
Pbar.Value =i;
PbarV = Pbar.Value;
} }但这样做了后,F2启动正确,但F1也显示了。如何做能让F2下载完成后 才显示F1。
{
F2 f2 = new F2();
f2.Show();
}
F2窗体里面下载文件,我用的是异步,来实现进度条效果,代码如下:private void F2_Load(object sender, EventArgs e)
{
Start_DownFile(string URL, string FileNamePath);
} //定义委托
delegate void Delegate_DownFile(string URL, string FileNamePath); //回调函数
private void CallBackMethod_DownFile(IAsyncResult ar)
{
Delegate_DownFile dn = (Delegate_DownFile)ar.AsyncState;
} //用线程方式启动
private void Start_DownFile(string URL, string FileNamePath)
{
Delegate_DownFile dn = new Delegate_DownFile(DownFile);
AsyncCallback acb = new AsyncCallback(CallBackMethod_DownFile);
IAsyncResult iar = dn.BeginInvoke(URL, FileNamePath, acb, dn); } //下载文件
private void DownFile(string URL, string FileNamePath)
{ try
{
WebClient client = new WebClient(); //下载过程中
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
//下载完成
client.DownloadFileCompleted += client_DownloadFileCompleted; Uri uri = new Uri(URL);
client.DownloadFileAsync(uri, FileNamePath);
}
catch (UriFormatException ex)
{
} } private void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
SetStatus1(e.ProgressPercentage);
}delegate void SetTextCallback1(int i); public void SetStatus1(int i)
{
if (this.Pbar.InvokeRequired)
{
SetTextCallback1 d = new SetTextCallback1(SetStatus1);
this.Invoke(d, new object[] { i });
}
else
{
Pbar.Value =i;
PbarV = Pbar.Value;
} }但这样做了后,F2启动正确,但F1也显示了。如何做能让F2下载完成后 才显示F1。
解决方案 »
- vs2010如何将.net framework和.exe一起打包
- c#和matlab混合编程时的数据转换问题,关于mwarray和object
- 未将对象引用设置到对象的实例 session 问题出在哪儿了呢!!!
- 可以从句柄HImageList 构建 ImageList吗?
- 急需一个winform下使用的html编辑器,给50分了。挚谢。
- datagrid控件的几个操作问题
- 再请孟子,速马,思归等大侠给指点一下webform多线程的问题
- 求实现不规则形状画笔的代码或思路
- 大家新年好,我不知道怎么样才能在2003下开发的windows软件在xp里使用?
- .net2.0bata 对以前的版本程序支持怎样?
- 大家来看一下,这是不是一个倒分帖
- 定义一个DataSet的对象,如何在2个按钮下起作用?
private void F1_Load(object sender, EventArgs e)
{
F2 f2 = new F2();
this.Hide();
f2.Show();
}
F2窗体里面下载文件,我用的是异步,来实现进度条效果,代码如下: private void F2_Load(object sender, EventArgs e)
{
Start_DownFile(string URL, string FileNamePath);
} //定义委托
delegate void Delegate_DownFile(string URL, string FileNamePath); //回调函数
private void CallBackMethod_DownFile(IAsyncResult ar)
{
Delegate_DownFile dn = (Delegate_DownFile)ar.AsyncState;
} //用线程方式启动
private void Start_DownFile(string URL, string FileNamePath)
{
Delegate_DownFile dn = new Delegate_DownFile(DownFile);
AsyncCallback acb = new AsyncCallback(CallBackMethod_DownFile);
IAsyncResult iar = dn.BeginInvoke(URL, FileNamePath, acb, dn); } //下载文件
private void DownFile(string URL, string FileNamePath)
{ try
{
WebClient client = new WebClient(); //下载过程中
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
//下载完成
client.DownloadFileCompleted += client_DownloadFileCompleted; Uri uri = new Uri(URL);
client.DownloadFileAsync(uri, FileNamePath);
f2.Hide();
this.Show();//隐藏f2显示f1 }
catch (UriFormatException ex)
{
} } private void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
SetStatus1(e.ProgressPercentage);
} delegate void SetTextCallback1(int i); public void SetStatus1(int i)
{
if (this.Pbar.InvokeRequired)
{
SetTextCallback1 d = new SetTextCallback1(SetStatus1);
this.Invoke(d, new object[] { i });
}
else
{
Pbar.Value =i;
PbarV = Pbar.Value;
} }
{
F2 f2 = new F2();
this.Hide();//隐藏f1
f2.Show();
} //下载完成
client.DownloadFileCompleted += client_DownloadFileCompleted; Uri uri = new Uri(URL);
client.DownloadFileAsync(uri, FileNamePath);
f2.Hide();
this.Show();//隐藏f2显示f1
F2 f2 = new F2();
f2.Show();