/// <summary> /// 上传文件的按钮事件,打开文件视图,选择文件,开始上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Sendbtn_Click(object sender, EventArgs e) { string filePath = string.Empty; // 用来保存文件的绝对路径; this.isCancel = false; // 初始化为没有取消 //打开文件视图; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "D:\\"; openFileDialog.Title = "选择上传的文件"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath = openFileDialog.FileName; // 上传文件的绝对路径 IsUpload = true; // 标记在上传中; // 设置使用backgroundWorker processBarDiage = new ProcessBarDiage(); // 进度条 processBarDiage.TransfEvent += (bool judge) => { this.isCancel = judge; }; highestPercentageReached = 0; processBarDiage.Show(this); upLoad_fileWorker1.RunWorkerAsync(filePath); // 使用backgroundWorker } } }
// 打开新窗口,进度框 private void OpenProcess() { ProcessBarDiage barDiage = new ProcessBarDiage(); barDiage.TransfEvent += (bool judge) => { this.isCancel = judge; }; highestPercentageReached = 0; barDiage.label1.Text = $"正在下载\"{filesView.SelectedItem.ToString()}\""; barDiage.Show(); }