Click here to Skip to main content
15,886,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to show a different image to the gear that comes by default in a user control. When indicated attribute pointing to a file I get correctly, but when I wish to be embedded in the DLL as a resource can not.
Any help please?
How it works:
C#
[ToolboxBitmap(@"\\se41\noasistencial\ServTecnInfor348\Desarrollo\Imagenes\ControlesDeUsuarios\Ravisoft\rvsPanel.bmp")]
public class rvsPanel: System.Windows.Forms.Panel
{
 ...
}

C#
[ToolboxBitmapAttribute(typeof(Panel), "rvsPanel.bmp")]
public class rvsPanel: System.Windows.Forms.Panel
{
 ...
}

In the latter case the bmp is included as a project resource.
Posted
Updated 19-May-14 2:02am
v3
Comments
Kornfeld Eliyahu Peter 18-May-14 9:14am    
Este es un sitio en idioma Inglés - por favor, publicarlo en Inglés
DamithSL 18-May-14 9:23am    
i have converted to english using https://translate.google.com/?hl=en&tab=TT[^] Please correct if you know both languages
Kornfeld Eliyahu Peter 18-May-14 9:28am    
The problem is not me, but OP!!! As long as he can't post in English I suppose he can't get answers in English too...
[no name] 18-May-14 9:15am    
You have been a member for over 3 years and you still have not figured out that this is an English speaking site?
DamithSL 18-May-14 9:36am    
Por favor, utilice el traductor de google para convertir convertir español a Inglés o Inglés al español. Usted necesita para enviar preguntas en Inglés y recibirá respuestas en Inglés. aquí está el enlace al google translate https://translate.google.com/[^]

1 solution

It is not easy to understand what the MSDN documentation for this topic actually means.

Firstly I think the attribute is easier to understand if full names are used for the Type,
e.g.
C#
namespace ControlLib {
  [ToolboxBitmap(typeof(ControlLib.MyUserControl), "Bitmaps.red.bmp")]
  public partial class MyUserControl : UserControl {
    public MyUserControl() {
      InitializeComponent();
    }
  }
}


The name of the resource implied by that attribute is
resourcename = "ControlLib" + "." + "Bitmaps.red.bmp"

So how do we create the ControlLib.Bitmaps.red.bmp resource?

Assuming a project with the default namespace ControlLib
1) Add the file red.bmp to the Bitmaps subdirectory<br />
2) In Solution Explorer right click the file to get the properties page and change the Build Action from None to Embedded Resource


Note that a resource added in this way is not accessible via the designer generated strongly typed resource class ControlLib.Properties.Resources.

Any project referencing the ControlLib assembly should see custom toolbox bitmaps. In my rather old VS (c# express 2005) there are some difficulties
1) The default bitmaps are used when the assembly is added as a project reference.<br />
2) Custom bitmaps are not automatically refreshed and if changed must be deleted from the toolbox and readded via the Choose Toolbox Items dialog.


Finally I struggled to figure out when [ToolboxBitmap(Type)] would be used, but this note from 2006 (http://support.microsoft.com/kb/311315[^]) makes it clear that it allows you to use the custom bitmap from an existing control. For example if your custom control is a modified ProgressBar you may want to use that bitmap. Here's how:
C#
namespace ControlLib {
  [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))]
  public class MyProgressBar : ProgressBar {


Alan.
 
Share this answer
 
Comments
Emre Ataseven 19-May-14 16:27pm    
good answer, deserves a 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900