Microsoft KB Archive/836667

= How to set a custom bitmap image for a user control in Visual Studio .NET or in Visual Studio 2005 =

Article ID: 836667

Article Last Modified on 11/27/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-







IN THIS TASK

 * INTRODUCTION
 * Requirements
 * Create a user control
 * Add a bitmap file to the user control
 * Add the user control to the Visual Studio .NET Toolbox
 * REFERENCES



INTRODUCTION
This step-by-step article describes how to set a custom bitmap image for a user control. It also describes the specific property settings for the bitmap image and how to set the image as an icon for the user control.

back to the top

Requirements
This article assumes that you are familiar with the following topic:

How to develop user controls in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:

Microsoft Visual Studio .NET 2003, Visual Studio .NET 2002, or Visual Studio 2005

back to the top

Create a user control

 * 1) Start Visual Studio .NET or Visual Studio 2005.
 * 2) On the File menu, point to New, and then click Project.
 * 3) Under Project Types, click Visual Basic Projects.

Note In Visual Studio 2005, click Visual Basic.
 * 1) Under Templates, click Windows Control Library.
 * 2) In the Name box, type MyUserControl, and then click OK.

By default, a file that is named UserControl1.vb is created. By default, the UserControl class is also named UserControl1.

back to the top

Add a bitmap file to the user control

 * 1) On the File menu, click Add New Item.
 * 2) Under Templates, click Bitmap file.
 * 3) In the Name box, type UserControl1.bmp, and then click Open.

Note You must use the same name for the bitmap file as the name of the UserControl class that was created in the &quot;Create a user control&quot; section.
 * 1) Set the Height property and the Width property of the UserControl1.bmp file to 16.
 * 2) Set the Build Action property of the UserControl1.bmp file to Embedded Resource. To do this, click Embedded Resource in the list box that is associated with the Build Action property.
 * 3) In the editor, draw any image.
 * 4) On the Build menu, click Build Solution.

back to the top

Add the user control to the Visual Studio .NET or Visual Studio 2005 Toolbox

 * 1) In Solution Explorer, double-click the UserControl1.vb file.
 * 2) In the Toolbox, click the General tab, and then do the following, depending on the product version that you have:
 * 3) * In Visual Studio .NET 2002, right-click the General tab, and then click Customize Toolbox.
 * 4) * In Visual Studio .NET 2003, right-click the General tab, and then click Add/Remove Items.
 * 5) * In Visual Studio 2005, right-click the General tab, and then click Choose Items.
 * 6) Click the .NET Framework Components tab, and then click Browse.
 * 7) Locate and then click the MyUserControl.dll file.
 * 8) Click Open, and then click OK.

Notice that the user control is added to the General tab and that the icon is set to your custom bitmap image.

back to the top

