Windows Forms: How to read an image file in C#
By FoxLearn 7/11/2017 8:14:44 PM 3.37K
How to read and display image in C# using PictureBox control
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "ReadImageFile" and then click OK
Step 2: Design your form as below
Step 3: Add code to button click event handler as below
private void btnOpen_Click(object sender, EventArgs e) { try { //Open file dialog, allows you to select an image file using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPG|*.jpg|PNG|*.png|Bitmap|*.bmp", ValidateNames = true, Multiselect = false }) { if (ofd.ShowDialog() == DialogResult.OK) pictureBox.Image = Image.FromFile(ofd.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
VIDEO TUTORIALS
- How to Add Combobox to DataGridView in C#
- How to Create Multiple pages on the Form using Panel control in C#
- How to insert Math Equation to RichTextBox in C#
- How to Send and Receive email in Microsoft Outlook using C#
- How to Print Windows Form in C#
- How to Use Form Load and Button click Event in C#
- How to use Advanced Filter DataGridView in C#
- How to use TagListControl in C#