private void toolStripButtonDownload_Click(object sender, EventArgs e) { if (listViewFile.SelectedItems.Count == 1) { int index = listViewFile.SelectedIndices[0]; if (index >= selectedTreeNode.Nodes.Count)//如果是文件 { string dirpath = toolStripTextBoxCurDir.Text; string fileName = listViewFile.Items[index].SubItems[0].Text; string path = dirpath + "\\" + fileName; Send_forFileOperation("command,Download," + path); while (true) { try { Clients.client_FileTransport = new TcpClient(); Clients.client_FileTransport.Connect(selectAddress, Clients.port_FileTransport); Clients.netStream_FileTransport = Clients.client_FileTransport.GetStream(); break; } catch { continue; } } string msg = Clients.sr_op.ReadLine(); string[] str = msg.Split(','); if (str[0] == "success")//要下载的文件存在 { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = fileName; //默认保存文件的文件名 if (saveFileDialog.ShowDialog() == DialogResult.OK) { string savePath = saveFileDialog.FileName; DownloadProcessBar form = new DownloadProcessBar(savePath + "," + str[1]); form.ShowDialog(); } } else { MessageBox.Show("要下载的文件不存在"); } } else//是文件夹 { MessageBox.Show("只能下载文件!"); } } else { MessageBox.Show("请选择要下载的文件!"); } }