110,533
社区成员
发帖
与我相关
我的任务
分享
怎样点击按钮之后就给用户一个等待界面,frm.ShowDialog();就关闭那个等待的界面。?
private void btnAddFtpFile_Click(object sender, EventArgs e)
{
if (CheckPath() == false)//检测FTP是否可用,也要等。。。
{
MessageBox.Show(SetLanguage.getValues("frmExportFtp_ConntectionFailed", "frmExportFtp_Message"));
return;
}
frmFtpFileTree frm = new frmFtpFileTree(strip,strname,strpwd);
frm.ShowDialog();
// 点击按钮很久以后,这个frm才弹出来,我想在这个frm弹出来之前给用户一个等待的窗口。
//PicStatus.Visible = false;
this.txtFtpPath.Text = strpath.ToString();
}
public bool CheckPath()
{
string strip = txtFtpServer.Text.Trim().ToString();
string strname = txtFtpUserName.Text.Trim().ToString();
string strpwd = txtFtpPassword.Text.Trim().ToString();
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + strip));
req.Credentials = new NetworkCredential(strname, strpwd);
req.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
req.KeepAlive = false;
try
{
req.GetResponse();//这里也比较慢。。。。
return true;
}
catch
{
return false;
}
}
System.Threading.Thread th;
string strip = "";
string strname = "";
string strpwd = "";
bool blstr;
等待的无边框窗体 frm;
private void btnAddFtpFile_Click(object sender, EventArgs e)
{
strip = txtFtpServer.Text.Trim().ToString();
strname = txtFtpUserName.Text.Trim().ToString();
strpwd = txtFtpPassword.Text.Trim().ToString();
th = new System.Threading.Thread(new System.Threading.ThreadStart(CheckPath));
th.Start();
//这里可以打开一个等待的无边框窗体
frm = new 等待的无边框窗体();
frm.show();
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if(blstr != null)
{
timer1.Enabled = false;
//关闭已经打开的等待窗体
frm.close();
if(blstr == true)
{
frmFtpFileTree frm = new frmFtpFileTree(strip,strname,strpwd);
frm.ShowDialog();
this.txtFtpPath.Text = strpath.ToString();
}
else
{
MessageBox.Show(SetLanguage.getValues("frmExportFtp_ConntectionFailed", "frmExportFtp_Message"));
}
}
}
public void CheckPath()
{
blstr = null;
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + strip));
req.Credentials = new NetworkCredential(strname, strpwd);
req.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
req.KeepAlive = false;
try
{
req.GetResponse();//这里也比较慢。。。。
blstr = true;
}
catch
{
blstr = true;
}
}