I have been working at this a while but can't seem to figure it out!
I have a Solution that looks like the following layout...
Solution 'Gen' (2 projects)
'-> MyControls
'-> graphics
'-> UserControl1.bmp
'-> UserControl1.cs
'-> Gen
'-> MainGUI.cs
I want to simply make a toolbox icon so that I can see a nice icon on my toolbar instead of the blue-like gear (the default toolbox icon).
The steps I have currently taken...
1. Created A Bitmap Image:
I made a 16x16 pixel image that is 16 colors (4 bit).
2. Embed The Image As A Resource:
Clicked on the image in the Solution Explorer window, then in the properties window I changed the Build Action to "Embedded Resource".
3. Add An Internal Class Used To Fix A Bug In The GetImageFromResource() Method:
BEFORE the namespace declare I added the following lines...
internal class resfinder
{
}
4. Add The Class Property 'ToolboxBitmap':
Above the class declaration...
public partial class UserControl1 : UserControl
I added the following line...
[ToolboxBitmap(typeof(resfinder), "Gen.graphics.UserControl1.bmp")]
5. Build Project:
Under the Build menu I used "Rebuild Solution".
ENTIRE BLOCK OF CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
internal class resfinder
{
}
namespace Gen
{
[ToolboxBitmap(typeof(resfinder), "Gen.graphics.UserControl1.bmp")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
}
RESULTS:
I still have the little blue-like gear as a toolbox icon when I try to use it on the MainGUI.cs form.
Sources:
It seems the answer is simple... I have actually done everything right!
There is a small thing worth noting though...
The custom toolbox icon will NOT show up if you are using a reference to a project in the same solution.
To fix/workaround this you need to do the following...
Add a reference to the compiled (product of the custom control project) DLL file instead.
I ended up removing the custom control project after compiling it and then adding a reference to my project that I wanted to use it on. After I did that I right clicked in the Toolbox then clicked "Choose Items...". Then clicked Browse and loaded the DLL from there.
Now the custom toolbox icon shows up just fine!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With