Displaying Graphics on a Form

See Also4M0DYWF

You can add graphics to forms5272EF and controlsXX9KJT at design timeCFSL0V by setting the Picture property in the Properties windowO00AW8 or by copying graphics from other applications and pasting them into Visual Basic.  A graphic can be displayed either as a foreground graphic, using a picture box3W9LV25 or image control5KPW0U3 as the display area for a bitmap1MF6V4R, icon529QBG, or metafile13MILUI, or as a background graphic, using the entire Form windowVK6SGD as the display area.  You can also add graphics at run timeCYRM35 with code.

To add a foreground graphic at design time using the Properties window

   1. Draw2JRMWVS a picture box or image control on the form.

   2. In the Properties window1K6JQPY, select Picture4GBE5Q.

     In the Settings boxAV4YN4, Visual Basic displays the current type of image and the down arrow to the right of the Settings box changes into a button with three dots51NRBM.

   3. Click the button with three dots.

     Visual Basic displays the Load Picture dialog box.

   4. In the dialog box, select or type the name of the graphic file you want.

   5. Choose OK.

     Visual Basic displays the graphic inside the picture box.  If necessary, resize the picture box.


To add a background graphic at design time using the Properties window

   1. Click a blank part of the form to select it.

   2. From the Properties window, select Picture.

   3. Follow steps 3-5 as listed above.

     Visual Basic displays the graphic inside the Form window.  If necessary, resize the form.


To add a graphic at design time by copying and pasting

   1. Open the other application and copy the graphic to the Clipboard.

   2. Switch to Visual Basic.

   3. Select the form or control onto which you want to paste the graphic.

   4. From the Edit menu, choose Paste (Ctrl+V).


Note   To delete a graphic at design time, select the Picture property in the Properties window and delete the contents of the Settings box.

Full-screen bitmaps for forms can be memory-intensive.  To save memory, use a picture box or image control to display a foreground graphic.

When using a Picture box, set the AutoSize2ZZ9BBZ property to True to automatically resize the control to fit the picture.  When Autosize is set to False, the size of the control remains constant and graphics are clipped when they exceed the area of the control.


See Also


Drawing Lines and Shapes on a Form1UQ38LN


Picture Box Control31MYIWX

Setting Form and Control Properties1NFIWMG

Using Icons6AQG8GG


Learning Visual Basic:

Using Color and Graphics


Programmer's Guide:

Chapter 15, "Creating Graphics for Applications"