How to load Image in C# and set properties of the Picture Box

Posted by SAMIR BHOGAYTA on Samir ASP.NET with C# Technology See other posts from Samir ASP.NET with C# Technology or by SAMIR BHOGAYTA
Published on 2010-02-09T01:22:00.000-08:00 Indexed on 2010/12/06 17:00 UTC
Read the original article Hit count: 262

Create a C# application drag a picture Box, four buttons and open file dialog on the form.
Write code on btn_browse Button click
-----------------------------------------
private void btn_browse_Click(object sender, System.EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog()==DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
}
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
Write code on btn_StretchImage Button click
------------------------------------------------
private void btn_StretchImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
}
Write code on btn_AutoSize Button click
-------------------------------------------------
private void btn_AutoSize_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
}
Write code on btn_CenterImage Button click
--------------------------------------------------
private void btn_CenterImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
}


© Samir ASP.NET with C# Technology or respective owner

Related posts about How to load Image in C# a