© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

  HomeSource Code DotNet ► C# ▼

Picture Box Demo

Picture box, which receives the path of image from string variable and displays the images with decided property when application will get run.
Form1.Designer.cs

namespace gui
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;

       
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

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

namespace gui
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void SetPictureBoxSizeMode()
        {
            string path = @"C:\Pictures\0281012L.JPG";  // Change the path if needed.

            pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
            pictureBox1.Image = Image.FromFile(path);

            pictureBox2.SizeMode = PictureBoxSizeMode.Normal;
            pictureBox2.Image = Image.FromFile(path);

            pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox3.Image = Image.FromFile(path);

            pictureBox4.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox4.Image = Image.FromFile(path);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SetPictureBoxSizeMode();
        }

    }
}

 

SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom