Drawing an Image on a Form
In this lesson, you will learn how to display an image using graphics calls.
In an earlier lesson, you learned how to display an image using a PictureBox control. It is also possible to display an image from a file using the graphics methods in Visual Basic. As with the previous lesson, using the graphics methods instead of a PictureBox control is a necessity if you want to do something special, such as rotate the image.
To display a rotated image
On the File menu, choose New Project.
On the Templates pane, in the New Project dialog box, click Windows Forms Application.
In the Name box, type DrawImage and then click OK.
A new Windows Forms project opens.
In Solution Explorer, double-click the My Project node to open the Project Designer.
In the Project Designer, click the Resources tab, select Add Resource, and then select Add Existing File.
In the Add existing file to resources dialog box, browse to any image file and select it, and then click Open.
In Solution Explorer, select the Form1 node, and then on the View menu, select Code to open the Code Editor.
In the Code Editor, select Paint from the Events drop-down list.
In the Form1_Paint event handler, add the following code.
In My.Resources.picture, replace picture with the name of the image file that you added to the project resources in an earlier step.
Press F5 to run the program. You should see the rotated image on the form.
In this lesson, you learned how to display a rotated image on a form. That completes the lessons on graphics. In the next set of lessons, you will learn how to share the programs you create.
Next Lesson: Distributing a Program