Solved

Yet another saga of the failing ToolboxBitmap

Posted on 2009-03-31
6
384 Views
Last Modified: 2012-05-06
Attempting to get an icon/bitmap to be displayed with my UserControl, but failing miserably.
1.) There is a bit map for this control "ctrlBankBitSW.bmp
2.) The bit map has been set to a build oaction of "Embedded Resource"
3.) The project is set to "Class Library"

What am I missing?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
 
namespace libSigCntrl
{
   //[ToolboxBitmap(@"ctrlBankBitSW.bmp")]
   public partial class ctrlBankBitSW : UserControl
   {
      public ctrlBankBitSW()
      {
         InitializeComponent();
      }
   }
}

Open in new window

0
Comment
Question by:graber
  • 4
6 Comments
 
LVL 14

Expert Comment

by:jjardine
ID: 24035301
Looks like the Toolbox Attribute is commented out?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24038699
How to: Provide a Toolbox Bitmap for a Control
http://msdn.microsoft.com/en-us/library/4wk1wc0a.aspx from microsoft
rest all the samples on the net were saying about giving the fully qualified path for the bitmap but the 3rs sample from microsoft did not use that approach
try, it might work
0
 
LVL 2

Author Comment

by:graber
ID: 24040350
sorry about that jjardine... the comment was intentional.. I failed to remove before posting.  But even with the comment it still fails.
namespace libSigCntrl
{
   [ToolboxBitmap(typeof(ctrlBitSW),@"ctrlBitSW.bmp")]
   public partial class ctrlBitSW : UserControl
   {
      public ctrlBitSW()
      {
         InitializeComponent();
      }
   }
}
 
namespace libSigCntrl
{
   [ToolboxBitmap(typeof(ctrlBankBitSW),"ctrlBankBitSW")]
   public partial class ctrlBankBitSW : UserControl
   {
      public ctrlBankBitSW()
      {
         InitializeComponent();
      }
   }
}

Open in new window

testimg.jpg
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:graber
ID: 24053138
According to a Microsoft MSDN form for C# and http://www.bobpowell.net/toolboxbitmap.htm
the source should look like the code Snippet

But I still don't show the images for either of the UserControls
ctrlBitSW.cs
namespace libSigCntrl
{
   [ToolboxBitmap(typeof(ctrlBitSW_res), "libSigCntrl.ctrlBitSW.bmp")]
   public partial class ctrlBitSW : UserControl
   {
      public ctrlBitSW()
      {
         InitializeComponent();
      }
   }
}
 
internal class ctrlBitSW_res{}
------------
ctrlBankBitSW.cs
namespace libSigCntrl
{
   [ToolboxBitmap(typeof(ctrlBankBitSW_res), "libSigCntrl.ctrlBankBitSW.bmp")]
   public partial class ctrlBankBitSW : UserControl
   {
      public ctrlBankBitSW()
      {
         InitializeComponent();
      }
   }
}
internal class ctrlBankBitSW_res { }

Open in new window

testimg.jpg
0
 
LVL 2

Accepted Solution

by:
graber earned 0 total points
ID: 24103177
The particulars the developement enviorment:
Microsoft Visual Studio 2005
Version 8.0.50727.867  (vsvista.050727-8600)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
Microsoft Visual C# 2005   77626-009-2070057-41395
Microsoft Visual C# 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)  
This service pack is for Microsoft Visual Studio 2005 Professional Edition - ENU.
Update for Microsoft Visual Studio 2005 Professional Edition - ENU (KB932232)  
This Update is for Microsoft Visual Studio 2005 Professional Edition - ENU.

Well the explaination is: It's a bug.  
But the good news is there is a workaround.  The reason that it works will require some more investigation on my part but this will work.

1.) Add a bitmap to your project space with the same name as the class that it will be used to represent it.  Once you've added it it will be right above the class that will be using it.
2.) Add the end of class to use the bit map add:
     internal class <name>_res{}
     The <name> is what ever you called the class followed by "_res{}".
3.) Add the ToolBoxBitmap as follows:
     [ToolboxBitmap(typeof(<name>_res), "<project name>.<name>.bmp")]
4.) After compiling right click on the "Toolbox" palette and choose the "Choose Item" option. Then when the "Choose Toolbox Items" Dialog appears select "Browse".  Locate the dll for the control you are developing and select "Open".

The bitmap that you created for your control wil show up on the "Toolbox Palette"
0
 
LVL 2

Author Comment

by:graber
ID: 24134545
5.) On the properties for the bmp file change the Build Action Option to "Embedded Resource"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question