Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using Newtonsoft.Json.Linq;
using System.Net;
using Newtonsoft.Json;
namespace WinFormImgUpload
{
public partial class Form1 : Form
{
//图片服务器路径
public string _ApiUrl = "http://localhost:8383/ImgService.asmx/UpFileImg";
public string _ImgUrl = "http://localhost:8383";// http://localhost:3137
public string _ApiUrlDel = "http://localhost:8383/ImgService.asmx/DelUpFileImglocal";
public string ApiUrl { get { return _ApiUrl; } set { _ApiUrl = value; } }
public string ApiUrlDel { get { return _ApiUrlDel; } set { _ApiUrlDel = value; } }
public string ImgUrl { get { return _ImgUrl; } set { _ImgUrl = value; } }
public Form1()
{
InitializeComponent();
}
private void btnSltImg_Click(object sender, EventArgs e)
{
flowLayoutPanel1.Controls.Clear();
ofdImage.Dispose();
//指定查找的文件类型
ofdImage.Filter = "@.Jpg|*.jpg|@.Png|*.png|@.Gif|*.gif|@.All files|*.*";
//该对话框会返回一个DialogResult类型的值,DialogResult.OK或者DialogResult.NO
DialogResult dr = ofdImage.ShowDialog();
if (dr == DialogResult.OK)
{
for(int i=0;i<ofdImage.FileNames.Length;i++)
{
PictureBox pbox = new PictureBox();
pbox.Name = "pbox" + i;
pbox.Size = new System.Drawing.Size(180, 200);
pbox.SizeMode=PictureBoxSizeMode.Zoom;
pbox.Image=Image.FromFile(ofdImage.FileNames[i]);
pbox.Click+=new EventHandler(pbox_Click);
pbox.BorderStyle = BorderStyle.FixedSingle;
flowLayoutPanel1.Controls.Add(pbox);
}
}
}
private void pbox_Click(object sender, EventArgs e)
{
PictureBox pboxs = (PictureBox)sender;
ImageZoomMainForm imgzm = new ImageZoomMainForm(pboxs.Image);
imgzm.imgx = 0;
imgzm.imgy = 0;
imgzm.startx = 0;
imgzm.starty = 0;
imgzm.ShowDialog();
}
private void btnUpLoad_Click(object sender, EventArgs e)
{
if (ofdImage.FileNames.Length < 1)
{
MessageBox.Show("请先选择图片文件");
return;
}
if (bgWorker.IsBusy)
return;
this.progressBar1.Maximum = 100;
//向业务内部传递处理数据的方法,传递集合,数值之类的
bgWorker.RunWorkerAsync();
}
private void btnStop_Click(object sender, EventArgs e)
{
//取消操作会执行此方法
bgWorker.CancelAsync();
}
//业务内部处理大量数据的地方,后台默默处理数据。(关于界面控件的东西,这里不要出现,比如给控件赋值,这里不要出现)
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
object s = e.Argument;//这里的e.Argument就是上面传递的参数 111
if (bgWorker.CancellationPending)
{
e.Cancel = true;
return;
}
else