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;
}
不足之点请大家指点一下。