I’m doing an imageviewer. I’ve already done importing the image in the picture box.
Which code should be used to autosize the image in the picture box? Here’s my code in Viewing the image in picture box.
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]);
}
}
Take a look at the
SizeModeproperty of thePictureBox: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspxSet this to
AutoSizeand you’re ready to go.Check here what you can set it to