Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-set-the-image-displayed-by-a-windows-forms-control.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.5 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Set the Image Displayed by a Control 08/20/2019
csharp
vb
cpp
Button control [Windows Forms], images
Windows Forms controls, images
controls [Windows Forms], images
images [Windows Forms], Windows Forms controls
examples [Windows Forms], controls
9445af8f-4f62-48b0-a3f6-068058964b9f

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.

Programmatic

Set the control's Image or BackgroundImage property to an object of type xref:System.Drawing.Image. Generally, you'll be loading the image from a file by using the xref:System.Drawing.Image.FromFile%2A 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 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 xref:System.Windows.Forms.PictureBox control added.

' Replace the image named below with your own icon.
PictureBox1.Image = Image.FromFile _
   (System.Environment.GetFolderPath _
   (System.Environment.SpecialFolder.MyPictures) _
   & "\Image.gif")
// Replace the image named below with your own icon.
// Note the escape character used (@) when specifying the path.
pictureBox1.Image = Image.FromFile
   (System.Environment.GetFolderPath
   (System.Environment.SpecialFolder.MyPictures)
   + @"\Image.gif");
// Replace the image named below with your own icon.
pictureBox1->Image = Image::FromFile(String::Concat
   (System::Environment::GetFolderPath
   (System::Environment::SpecialFolder::MyPictures),
   "\\Image.gif"));

Designer

  1. In the Properties window of Visual Studio, select the Image or BackgroundImage property of the control, and then select the ellipsis (Ellipsis button in Visual Studio) to display the Select Resource dialog box.

  2. Select the image you want to display.

See also