Using the PictureBox Control

Using the PictureBox Control

The PictureBox control is used to simplify the work required to display images. Using a PictureBox control, you can simply create an instance of the PictureBox class and assign a few properties. Most of the work required to properly display the image is encapsulated by the PictureBox class.

The most important property exposed by the PictureBox class is the Image property, which is used to specify the image that’s displayed in the control, as shown here:

pictureBox.Image = Image.FromFile(@"C:\Windows\winnt256.bmp");

In many cases, the image and the PictureBox control will be different sizes. The SizeMode property specifies how the image and the PictureBox control are sized in relation to each other. This property uses values from the Picture­BoxSizeMode enumeration, listed in Table 15-1.

Part III: Programming Windows Forms