6.11. Adding a PictureBox Control

The simplest way of displaying an image is through the PictureBox control. The steps to do this are as follows:

1.
Click on PictureBox in the Windows Forms Toolbox window and drag it onto the form.
2.
In the Properties box, in the Image entry, click on the right-hand gray box.
3.
An open-file dialog box pops up. Select an image for the dialog to open. When you click Open, the image is displayed within the picture box as, for example, in Figure 6.17.
Figure 6.17. A Simple Use of the PictureBox Control

4.
Resize the picture box to best display the image.

As a somewhat more complex example, let's add event handling ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.