Windows Forms: How to Upload/Display Image In Picture Box Using C#
By FoxLearn 9/17/2020 4:32:08 AM 9.46K
This post shows you How to Upload/Display Image In Picture Box Using C# Windows Forms Application.
Dragging PictureBox, TextBox, Button control from your Visual Studio toolbox into your form designer. You can modify your layout as shown below.
How to show image in picturebox in c# using openfiledialog
Adding a click event handler to the Upload button allows you to select an image file, then display the image in your PictureBox control.
How to display image in picturebox in c#
private void btnUpload_Click(object sender, EventArgs e) { //c# open file dialog with image filters using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png" }) { if (ofd.ShowDialog() == DialogResult.OK) { //c# display image in picture box pictureBox1.Image = new Bitmap(ofd.FileName); //c# image file path txtFileName.Text = ofd.FileName; } } }
Using OpenFileDialog class with the Filter property allows the user to select only valid image files, then display image in picturebox in c# using path.
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
What Are RESTful Web Services?
02/19/2024