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();
}
}
}
OUTPUT
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();
}
}
}
OUTPUT