2012-11-15 31 views
1

我在做一個圖片查看器。我已經完成了在圖片框中導入圖片的工作。在圖片框中自動調整圖片

哪些代碼應該用於自動調整圖片框中的圖片?這是我在查看圖片框中的圖片的代碼。

private void button1_Click(object sender, EventArgs e) 
    { 
     OpenFileDialog openFileDialog = new OpenFileDialog(); 
     openFileDialog.Multiselect = true; 
     openFileDialog.Filter = "JPEG|*.jpg|Bitmaps|*.bmp"; 

     if (openFileDialog.ShowDialog() == DialogResult.OK) 
     { 
      pFileNames = openFileDialog.FileNames; 
      pCurrentImage = 0; 
      ImageView(); 
     } 
    } 

    protected void ImageView() 
    { 
     if (pCurrentImage >= 0 && pCurrentImage <= pFileNames.Length - 1) 
     { 
      pictureBox1.Image = Bitmap.FromFile(pFileNames[pCurrentImage]); 
     } 
    } 
+0

你要自動調整圖像本身,或者PictureBox的? – AssaultingCuccos

+0

我認爲這是picturbox1.SizeMode = SizeMode.Zoom。你會在圖片框的屬性中找到它。 – WozzeC

+0

@弗羅里斯圖像先生.. – Jay

回答

0

您可以嘗試將PictureBox上的SizeMode屬性設置爲AutoSize。

1

檢查PictureBox.SizeMode Property並根據需要PictureBox控件同時顯示圖像做由PictureBoxSizeMode Enumeration設置。

  • AutoSize意味着PictureBox將適合圖像。

如果你想圖像適合圖片框然後設置sizemode到StretchImage

// Set the SizeMode property to the StretchImage value. 
// This will enlarge the image as needed to fit into 
// the PictureBox. 
    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;