2013-07-08 66 views
0

我想从列表显示图片到图片框。 我的图像在图片框中显示,但问题是它显示列表中定义的图片框中图片的大小。任何人都可以告诉我如何放大我的图像大小?从列表视图显示图像到图片框

这里是我的一段代码:

private void listView_SelectedIndexChanged(object sender, EventArgs e) 
    { 
      foreach (ListViewItem itm in listView.SelectedItems) 
     { 
      int imgIndex = itm.ImageIndex; 
      if (imgIndex >= 0 && imgIndex < this.documents.Images.Count) 
      { 
       // this.documents.Images[imgIndex].Width = 417; 

       pictureBox.Image = this.documents.Images[imgIndex]; 
      } 
     } 
    } 

,这是我如何从数据库中获取的图像:

ImageList documents = new ImageList(); 

if (documents.Images.Count < 1) 
     { 
      MessageBox.Show("No Documents Found."); 
     } 
     else 
     { 
     // pictureBox.Image = documents.Images[1]; 
      this.listView.View = View.LargeIcon; 
      documents.ImageSize = new Size(256, 256); 
      listView.LargeImageList = documents; 

      listView.Items.Clear(); 

      for (int j = 0; j < documents.Images.Count; j++) 
      { 
       ListViewItem item = new ListViewItem(); 
       item.ImageIndex = j; 
       this.listView.Items.Add(item); 
      } 
     } 

回答

0

PictureBox具有一个用于操纵图像尺寸SizeMode属性:

pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;

更多关于MSDN

+0

我做到了。但仍然有问题。图片中的图片不清晰。请看我编辑的问题。 –

0
-Create a new imagelist (imagelist1)** 
-Add images to your imagelist 
-Create a new listview (listview1) 
-Create a picturebox (picturebox1) 
-Create a new button (button1) 
-Create another button (button2)** 

    -Import images from imagelist1 to listview1 

private void button1_Click(object sender, EventArgs e) 
{ 
    listView1.Scrollable = true; 
    listView1.View = View.LargeIcon; 
    imageList1.ImageSize = new Size(100, 100); 
    listView1.LargeImageList = imagelist1; 

    for (int i = 0; i < imagelist1.Images.Count; ++i) 
    { 
     string s = imagelist1.Images.Keys[i].ToString(); 
     ListViewItem lstItem = new ListViewItem(); 
     lstItem.ImageIndex = i; 
     lstItem.Text = s; 
     listView1.Items.Add(lstItem); 
    } 
} 

- Set the selected image into your picture box from listview 

    private void button2_Click(object sender, EventArgs e) 
{ 
    if (this != null && listView1.SelectedItems.Count > 0) 
    { 
     ListViewItem lvi = listView1.SelectedItems[0]; 
     string imagekeyname = lvi.Text; 

     if (this.pictureBox1.Image != null) 
     { 
      this.pictureBox1.Image.Dispose(); 
      this.pictureBox1.Image = null; 
     } 

     //set the selected image into your picturebox 
     this.pictureBox1.Image = imagelist1.Images[imagekeyname]; 

    } 
}