Solved – ToolboxBitmap problem


Another small but  hard problem of asp.net that adding toolboxbitmap to your custom control.endlich it solved.

instructions: create a new class library project, name it ClassLibrary1. 

 Add a bitmap to your solution and name it “MyButton.bmp” (should be 16×16).Name must be same as your class name.  Click the bitmap in the Solution Explorer and change the Build Action to “Embedded Resource”.
!!! Do not add image directly in Resouce.resx file designer or resource folder.I tried it doesnt work.

Write your control class code like this:

using System;
using System.Drawing;
using System.Windows.Forms;

internal class resfinder { }

namespace MyControls
{
      [ToolboxBitmap(typeof(resfinder), "ClassLibrary1.MyButton.bmp")]
      public class MyButton : Button
      {

      }
}


The “resfinder” class is a trick to let the GetImageFromResource() method find the bitmap resource in the proper namespace.  This is necessary because I made the namespace for the control (“MyControls”) different from the default namespace of the class library (“ClassLibrary1”).  The resfinder type reference forces .NET to look for the bitmap resource in “ClassLibrary1.MyButton.bmp” rather than “MyControls.ClassLibrary1.MyButton.bmp”.

Build the project.  Open the project that will use your control.  Right-click the tool box and select “Choose items…”.  Click on Browse and select the ClassLibrary1.dll assembly.  You should now see the MyButton control with the proper bitmap.

http://social.msdn.microsoft.com/Forums/en/Vsexpressvcs/thread/4bd5a9cd-4730-41f6-a123-cb49b9ea420b

Advertisements

About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: