Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C# PictureBox Control



The Windows Forms PictureBox control is used to display images in a bitmap, GIF, icon, or JPEG formats.

C# PictureBox Control

The Windows Forms PictureBox control is used to display images in the bitmap, GIF, icon, or JPEG formats.

You can set the Image property to the Image you want to display, either at design time or at run time. You can programmatically change the Image displayed in a picture box, which is particularly useful when you use a single form to display different pieces of information.

pictureBox1.Image = Image.FromFile("c:\\testImage.jpg");

The SizeMode property, which is set to values in the PictureBoxSizeMode enumeration, controls the clipping and positioning of the image in the display area.

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

There are five different PictureBoxSizeMode is available to PictureBox control.

  1. AutoSize – Sizes the picture box to the image.
  2. CenterImage – Centers the image in the picture box.
  3. Normal – Places the upper-left corner of the image at upper left in the picture box
  4. StretchImage – Allows you to stretch the image in code

The PictureBox is not a selectable control, which means that it cannot receive input focus. The following C# program shows how to load a picture from a file and display it in streach mode.

using System;
using System.Drawing;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = Image.FromFile("c:\\testImage.jpg");
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        }

    }
}

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More