Solved

Yet another saga of the failing ToolboxBitmap

Posted on 2009-03-31
6
379 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling arrays 14 35
comparing string in C# 3 34
c# if statement weird reaction 3 30
COnsume rest client 6 15
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now