Example with PictureBox:-



Add a new Form i.e.,FormPicture to the Windows Application WABasics

Create one label,one  button and one pictureBox,one openFileDialog& set the following properties to them

[openFileDialog1 will only appear in the Component Tray]

label1:

     Text       :         Select Any Image
     Name     :         lblSample

button1:
     Text       :         Browse…
     Name     :         btnBrowse

pictureBox1:-

Name          :         PictureBox1
Size             :         300,300
         

Design :-



 Generate the EventHandler for btnBrowse Click Event
& write the following code in Source[FormPictureBox.cs] 


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WABasics
{
    public partial class FormPictureBox : Form
    {
        public FormPictureBox()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Jpeg Files|*.Jpg|Giff Files|.Gif|BitMap Files|.Bmp";
            openFileDialog1.ShowDialog();
            //pictureBox1.ImageLocation = openFileDialog1.FileName;
            pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
        }

        private void lblSample_Click(object sender, EventArgs e)
        {

        }

       
    }
}




Result :-


No comments:

Post a Comment