private void bentoButton_Click(object sender, EventArgs e) { var form = new BoxListForm(); if (form.ShowDialog() == DialogResult.OK) { nameTextBox.Text = Path.GetFileNameWithoutExtension(form.SelectUrl); urlTextBox.Text = form.SelectUrl; } }
private void boxButton_Click(object sender, EventArgs e) { boxButton.Enabled = false; var form = new BoxListForm(); if (form.ShowDialog() == DialogResult.OK) { var fileName = Path.Combine(vagrantDirectoryTextBox.Text, Path.GetFileName(form.SelectUrl)); var uri = new Uri(form.SelectUrl); boxFileNameToolStripStatusLabel.Visible = true; boxFileToolStripSplitButton.Visible = true; boxFileToolStripProgressBar.Visible = true; boxFileNameToolStripStatusLabel.Text = Path.GetFileName(form.SelectUrl); boxFileToolStripSplitButton.Text = string.Format("0/0Mbyte"); _downloadClient = new WebClient(); _downloadClient.DownloadProgressChanged += (s, ea) => { boxFileToolStripSplitButton.Text = string.Format("{0}/{1}Mbyte", ea.BytesReceived / 1024 / 1024, ea.TotalBytesToReceive / 1024 / 1024); boxFileToolStripProgressBar.Value = (int)ea.ProgressPercentage; }; _downloadClient.DownloadFileCompleted += (s, ea) => { if (ea.Error != null) { Console.WriteLine("エラー:{0}", ea.Error.Message); } else if (ea.Cancelled) { Console.WriteLine("キャンセルされました。"); } else { Console.WriteLine("ダウンロードが完了しました。"); } boxFileNameToolStripStatusLabel.Visible = false; boxFileToolStripSplitButton.Visible = false; boxFileToolStripProgressBar.Visible = false; boxButton.Enabled = true; }; _downloadClient.DownloadFileAsync(uri, fileName); } else { boxButton.Enabled = true; } }
private void boxButton_Click(object sender, EventArgs e) { boxButton.Enabled = false; var form = new BoxListForm(); if (form.ShowDialog() == DialogResult.OK) { var fileName = Path.Combine(vagrantDirectoryTextBox.Text, Path.GetFileName(form.SelectUrl)); var uri = new Uri(form.SelectUrl); boxFileNameToolStripStatusLabel.Visible = true; boxFileToolStripSplitButton.Visible = true; boxFileToolStripProgressBar.Visible = true; boxFileNameToolStripStatusLabel.Text = Path.GetFileName(form.SelectUrl); boxFileToolStripSplitButton.Text = string.Format("0/0Mbyte"); _downloadClient = new WebClient(); _downloadClient.DownloadProgressChanged += (s, ea) => { boxFileToolStripSplitButton.Text = string.Format("{0}/{1}Mbyte", ea.BytesReceived / 1024 / 1024, ea.TotalBytesToReceive / 1024 / 1024); boxFileToolStripProgressBar.Value = (int)ea.ProgressPercentage; }; _downloadClient.DownloadFileCompleted += (s, ea) => { if (ea.Error != null) Console.WriteLine("エラー:{0}", ea.Error.Message); else if (ea.Cancelled) Console.WriteLine("キャンセルされました。"); else Console.WriteLine("ダウンロードが完了しました。"); boxFileNameToolStripStatusLabel.Visible = false; boxFileToolStripSplitButton.Visible = false; boxFileToolStripProgressBar.Visible = false; boxButton.Enabled = true; }; _downloadClient.DownloadFileAsync(uri, fileName); } else { boxButton.Enabled = true; } }