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



The information in this article applies to:

  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

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.
  4. Under Templates, click Windows Control Library.
  5. 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 "Create a user control" section.
  4. Set the Height property and the Width property of the UserControl1.bmp file to 16.
  5. 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.
  6. In the editor, draw any image.
  7. 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:
    • In Visual Studio .NET 2002, right-click the General tab, and then click Customize Toolbox.
    • In Visual Studio .NET 2003, right-click the General tab, and then click Add/Remove Items.
    • In Visual Studio 2005, right-click the General tab, and then click Choose Items.
  3. Click the .NET Framework Components tab, and then click Browse.
  4. Locate and then click the MyUserControl.dll file.
  5. 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

Modification Type:MajorLast Reviewed:2/28/2006
Keywords:kbvs2005swept kbvs2005applies kbHOWTOmaster kbBitmap kbhowto KB836667 kbAudDeveloper