/// <summary> /// 下载图片按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem12_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GC.Collect(); tabNavigationPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textEdit1.Text)) { Form4 form4 = new Form4("错误:请求地址不合法"); form4.Text = "错误"; form4.ShowDialog(); barStaticItem1.Caption = "当前状态:取消图片请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textEdit1.Text)) { Form5 form5 = new Form5("警告:未检测到常规格式的下载地址,是否继续"); form5.Text = "警告"; form5.ShowDialog(); if (form5.DialogResult == DialogResult.Cancel) { barStaticItem1.Caption = "当前状态:取消图片下载"; return; } } barStaticItem1.Caption = "下载图片:" + Path.GetFileName(textEdit1.Text); xtraTabPage1.Controls.Clear(); xtraTabPage2.Controls.Clear(); html = String.Empty; Jhtml = String.Empty; #region 请求头配置 info = CreateHttp(); #endregion try { Image img = HttpMethod.DownPic(info); if (img == null) { Form4 form4 = new Form4("失败:下载失败"); form4.Text = "失败"; form4.ShowDialog(); return; } PictureEdit pictureEdit = new PictureEdit(); pictureEdit.Dock = DockStyle.Fill; pictureEdit.Image = img; tabNavigationPage1.Controls.Add(pictureEdit); } catch (Exception ex) { Form4 form4 = new Form4("程序错误:请联系程序员!"); form4.Text = "错误"; form4.ShowDialog(); } barStaticItem1.Caption = "下载图片:" + Path.GetFileName(textEdit1.Text) + "完毕"; }
/// <summary> /// 下载文件按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GC.Collect(); #region 请求头配置 info = CreateHttp(); #endregion xtraTabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textEdit1.Text)) { Form4 form4 = new Form4("错误:请求地址不合法"); form4.Text = "错误"; form4.ShowDialog(); barStaticItem1.Caption = "当前状态:取消文件下载"; return; } if (!RegexMethod.CheckRegex(checkurl, textEdit1.Text)) { Form5 form5 = new Form5("警告:未检测到常规格式的下载地址,是否继续"); form5.Text = "警告"; form5.ShowDialog(); if (form5.DialogResult == DialogResult.Cancel) { barStaticItem1.Caption = "当前状态:取消文件下载"; return; } } SaveFileDialog sf = new SaveFileDialog(); var arr = textEdit1.Text.Split('/'); String filename = arr[arr.Length - 1]; String type = filename.Split('.')[1]; String name = filename.Split('.')[0]; String filter = String.Format("{0}(*.{0})|*.{0}|所有文件(*.*)|*.*", type, type, type); sf.Filter = filter;//可以保存的格式 sf.FileName = arr[arr.Length - 1]; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (HttpMethod.DownLoadFile_ABPath(info, sf.FileName)) { Form4 form4 = new Form4("成功:下载成功"); form4.Text = "成功"; form4.ShowDialog(); } else { Form4 form4 = new Form4("失败:下载失败"); form4.Text = "失败"; form4.ShowDialog(); } } barStaticItem1.Caption = "当前状态:完毕"; }
/// <summary> /// 图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button10_Click(object sender, EventArgs e) { GC.Collect(); tabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("请求地址不合法"); toolStripStatusLabel1.Text = "取消图片请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textBox1.Text)) { DialogResult result = MessageBox.Show("未检测到常规格式的下载地址,是否继续", "警告", MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.Cancel) { toolStripStatusLabel1.Text = "取消图片请求"; return; } } toolStripStatusLabel1.Text = "下载图片:" + Path.GetFileName(textBox1.Text); tabPage1.Controls.Clear(); tabPage4.Controls.Clear(); tabPage5.Controls.Clear(); html = String.Empty; JsHtml = String.Empty; #region 请求头配置 info = CreateHttp(); #endregion try { Image img = HttpMethod.DownPic(info); if (img == null) { MessageBox.Show("下载失败"); } PictureBox box = new PictureBox(); box.Dock = DockStyle.Fill; box.Image = img; tabPage1.Controls.Add(box); } catch (Exception ex) { MessageBox.Show(ex.Message); } toolStripStatusLabel1.Text = "下载图片:" + Path.GetFileName(textBox1.Text) + "完毕"; }
/// <summary> /// 下载文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button11_Click(object sender, EventArgs e) { GC.Collect(); #region 请求头配置 info = CreateHttp(); #endregion tabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("请求地址不合法"); toolStripStatusLabel1.Text = "取消下载请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textBox1.Text)) { DialogResult result = MessageBox.Show("未检测到常规格式的下载地址,是否继续", "警告", MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.Cancel) { toolStripStatusLabel1.Text = "取消下载请求"; return; } } SaveFileDialog sf = new SaveFileDialog(); var arr = textBox1.Text.Split('/'); String filename = arr[arr.Length - 1]; String type = filename.Split('.')[1]; String name = filename.Split('.')[0]; String filter = String.Format("{0}(*.{0})|*.{0}|所有文件(*.*)|*.*", type, type, type); sf.Filter = filter;//可以保存的格式 sf.FileName = arr[arr.Length - 1]; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (HttpMethod.DownLoadFile_ABPath(info, sf.FileName)) { MessageBox.Show("下载成功"); } else { MessageBox.Show("下载失败"); } } toolStripStatusLabel1.Text = "完毕"; }