我正在做一个imageviewer.我已经完成了在图片框中导入图像.
应该使用哪个代码来自动调整图片框中的图像?这是我在查看图片框中的图片中的代码.
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]);
}
}
Run Code Online (Sandbox Code Playgroud)
看一下以下SizeMode属性PictureBox:http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx
把它设置为AutoSize,你准备好了.