PictureBox

Used to display an image on the form, at desired place.

API: System.Windows.Forms.PictureBox
Naming Convension: picxxxxxx
Properties of PictureBox
Property Description
Name Specifies the name of the control.
Image Specifies the image, which is to be displayed in the control.
SizeMode Specifies mode of the image sizing in the control. (Normal, Stretch, Auto Size, Center, Zoom)
BackColor, Enabled, Visible, Cursor, Size, Location, ContextMenuStrip

Events of PictureBox
Event Description
Click Executes when the user clicks on the picture box.
DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave

Demo on PictureBox

picturebox
Design
lblEnterImagePath
txtImagePath
btnShow
picBoxImage
btnClearImage
lblSizeMode
rbNormal
rbStretch
rbAutoSize
rbCenter
rbZoom


using System.IO;
private void btnShow_Click(object sender, EventArgs e)
{
string imagepath = txtImagePath.Text;
FileInfo fobj = new FileInfo(imagepath);
if (fobj.Exists)
{
picBoxImage.Image = Image.FromFile(imagepath);
}
else
{
MessageBox.Show("Image file not found.");
}
}
private void btnClearImage_Click(object sender, EventArgs e)
{
picBoxImage.Image = null;
}
private void rbNormal_CheckedChanged(object sender, EventArgs e)
{
picBoxImage.SizeMode = PictureBoxSizeMode.Normal;
}
private void rbStretch_CheckedChanged(object sender, EventArgs e)
{
picBoxImage.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void rbAutoSize_CheckedChanged(object sender, EventArgs e)
{
picBoxImage.SizeMode = PictureBoxSizeMode.AutoSize;
}
private void rbCenter_CheckedChanged(object sender, EventArgs e)
{
picBoxImage.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void rbZoom_CheckedChanged(object sender, EventArgs e)
{
picBoxImage.SizeMode = PictureBoxSizeMode.Zoom;
}