• 图片上传(控件ListView实现)


    效果图

    1.上传

     /// <summary>
            /// 上传
            /// </summary>
            private void Upload()
            {
                if (imgListPhoto.Images.Count > 12)
                {
                    MsgBox.Show("最多上传12张照片");
                    return;
                }
                if (openCertDialog.ShowDialog() == DialogResult.OK)
                {
                    FileInfo fileInfo = new FileInfo(openCertDialog.FileName);
                    try
                    {
                        if (imgListPhoto.Images.Count + openCertDialog.FileNames.Length > 12)
                        {
                            MsgBox.Show("最多上传12张照片");
                            return;
                        }
                        string[] nameArr = openCertDialog.FileNames;
                        this.lvImg.View = View.LargeIcon;
                        this.lvImg.LargeImageList = this.imgListPhoto;
                        this.lvImg.BeginUpdate();
                        foreach (var item in nameArr)
                        {
                            Image.FromFile(item);
                            //获取文件       
                            Image image = Image.FromFile(item);
                            //添加图片                    
                            imgListPhoto.Images.Add(image);
                            ListViewItem lvi = new ListViewItem();
                            lvi.ImageIndex = imgListPhoto.Images.Count - 1;
                            lvi.Text = imgListPhoto.Images.Count.ToString();
                            this.lvImg.Items.Add(lvi);
                            Thread.Sleep(200);
                        }
                        this.lvImg.EndUpdate();
                    }
                    catch
                    {
                        MsgBox.Show("请上传正确的图片格式");
                    }
                    if (openCertDialog.FileNames.Length > 0)
                    {
                        StringBuilder strSb = new StringBuilder();
                        foreach (var item in openCertDialog.FileNames)
                        {
                            strSb.Append(item + ",");
                        }
                        string names = strSb.ToString().Substring(0, strSb.ToString().Length - 1);
                        if (!string.IsNullOrEmpty(visitEmergencyModel.VtRlatpicidLst))
                        {
                            visitEmergencyModel.VtRlatpicidLst = visitEmergencyModel.VtRlatpicidLst + "," + names;
                        }
                        else
                        {
                            visitEmergencyModel.VtRlatpicidLst = names;
                        }
                    }
                    SetBtnSaveEnable(true);
                }
            }

    2.选中照片删除

    //选中图片

     selectImage = lvImg.SelectedItems[0];

     /// <summary>
            /// 删除图片
            /// </summary>
            private void DeletePt()
            {
                if (selectImage != null)
                {
                    if (this.lvImg.Items.Contains(selectImage))
                    {
                        this.lvImg.Items.Remove(selectImage);
                    }
                }
            }
  • 相关阅读:
    分布式缓存Redis
    MySQL优化
    SYSRET
    SYSCALL
    bolt cms V3.7.0 xss和远程代码执行漏洞
    github渗透测试工具库
    Gradle系列之Gradle插件
    fastjson 漏洞利用 命令执行
    linux 关闭对端口的监听
    微信小程序自动化测试最佳实践(附 Python 源码)
  • 原文地址:https://www.cnblogs.com/yuanshuo/p/13094038.html
Copyright © 2020-2023  润新知