How to: Set the Image Displayed by a Windows Forms Control


Several Windows Forms controls can display images. These images can be icons that clarify the purpose of the control, such as a diskette icon on a button denoting the Save command. Alternatively, the icons can be background images to give the control the appearance and behavior you want.

To set the image displayed by a control

  1. Set the control's Image or BackgroundImage property to an object of type Image. Generally, you will be loading the image from a file by using the FromFile method.

    In the following code example, the path set for the location of the image is the My Pictures folder. Most computers running the Windows operating system will include this directory. This also enables users with minimal system access levels to run the application safely. The following code example requires that you already have a form with a PictureBox control added.

    // Replace the image named below  
    // with an icon of your own choosing.  
    pictureBox1->Image = Image::FromFile(String::Concat