c#代码

1.、this.lvwBook.Items.Clear();//清空listview
                //遍历集合
                foreach (Book book in listBook)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = book.BookName;

                    string[] subItems = {book.BookType.BookTypeName,book.Author,book.Press,book.PubDate.ToString(),book.Pricing.ToString(),book.Page.ToString()};
                    item.SubItems.AddRange(subItems);//在item中添加多个值时用AddRange()方法。
                    this.lvwBook.Items.Add(item);
                    String imgPath = path + @"/CoverImgs/" + book.CoverImage;//获得图片的绝对路径
                    //判断图片是否存在,如果不存在显示默认的图片
                    if (!System.IO.File.Exists(imgPath))
                    {
                        imgPath = path + @"/CoverImgs/default.jpg";
                    }
                    //从绝对路径中获取图片
                    Image img = Image.FromFile(imgPath);
                    //设置图片
                    this.imgLstLarge.Images.Add(img);
                    this.imgLstSmall.Images.Add(img);
                    //添加图片索引
                    item.ImageIndex = this.imgLstSmall.Images.Count - 1;
 

2、 String imgPath = path + @"/CoverImgs/" + book.CoverImage;//获得图片的绝对路径
                    //判断图片是否存在,如果不存在显示默认的图片
                    if (!System.IO.File.Exists(imgPath))
                    {
                        imgPath = path + @"/CoverImgs/default.jpg";
                    }
                    //从绝对路径中获取图片
                    Image img = Image.FromFile(imgPath);
                    //设置图片
                    this.imgLstLarge.Images.Add(img);
                    this.imgLstSmall.Images.Add(img);
                    //添加图片索引
                    item.ImageIndex = this.imgLstSmall.Images.Count - 1;

3、if (this.lvwBook.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem item = this.lvwBook.SelectedItems[0];
            Book book = item.Tag as Book;
            String imgPath = path + @"/CoverImgs/" + book.CoverImage;
            if (!System.IO.File.Exists(imgPath))
            {
                imgPath = path + @"/CoverImgs/default.jpg";
            }
            Image img = Image.FromFile(imgPath);
            this.imgLstLarge.Images.Add(img);
            this.imgLstSmall.Images.Add(img);
            item.ImageIndex = this.imgLstSmall.Images.Count - 1;
            this.picCoverImg.Image = img;
            this.txtRemark.Text = book.Summary;

4、//创建打开文件对话框
            OpenFileDialog ofd = new OpenFileDialog();
            //设置过滤显示的文件类型
            ofd.Filter = "jpg文件|*.jpg|bmp文件|*.bmp|所有文件|*.*";
            //设置打开文件对话框的初始路径
            ofd.InitialDirectory = "E://";
            //显示打开文件对话框
            DialogResult dr = ofd.ShowDialog();
            //显示路径在文本框中
            if (dr == DialogResult.OK)
            {
                this.txtLiu.Text = ofd.FileName;
                Image img = Image.FromFile(ofd.FileName);
                this.picBookCoverImg.Image = img;
            }

不足之点请大家指点一下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值