C# WinForm多图片上传带进度条demo

C# WinForm多图片上传带进度条
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值