In: Computer Science
Using C#: Create a Form that consists of a PictureBox and 3 radio buttons. Assign an image of your choice to the PictureBox. Each radio button should be associated with a specific PictureBox size mode. When the user clicks on a specific radio button, the PictureBox's size mode should be changed to reflect the selection.
Below is the aolution
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ResizePictureBox
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
//radio button size100
click event
private void
Size100(object sender, EventArgs e)
{
pictureBox1.Size = new Size(100, 100); //set the picturebox
size
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //stretch
image
pictureBox1.BorderStyle = BorderStyle.Fixed3D; //border style
3d
}
//radio button size200
click event
private void
Size200(object sender, EventArgs e)
{
pictureBox1.Size = new Size(200, 200); //set the picturebox
size
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //stretch
image
pictureBox1.BorderStyle = BorderStyle.Fixed3D; //border style
3d
}
//radio button size300
click event
private void
Size300(object sender, EventArgs e)
{
pictureBox1.Size = new Size(300, 300); //set the picturebox
size
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //stretch
image
pictureBox1.BorderStyle = BorderStyle.Fixed3D; //border style
3d
}
private void
frmMain_Load(object sender, EventArgs e)
{
CenterToScreen(); //window center on the window
}
}
}
sample image: