March 19, 2010 .NET, HowTo, WindowsForms No comments
March 19, 2010 .NET, HowTo, WindowsForms No comments
I read about ToolboxBitmapAttribute and while doing my usual work have decided to use it.
First of all I created my UserControl named BufferedControl which should provide double buffering functionality for me. Once I finished with my control I navigated to Toolbox to add new tool like on the picture:
And do you know what happend next? It said to me that there is no controls which could be added to the Toolbox. But why? It is derived from UserControl and looks fine. So in order to see what is the difference I added empty UserControl1 and was able to add it to the Toolbox. I thought that the reason is because I do not have designer file for my control and some specific methods like Initialize(), but after I added them nothing helped. I did more research and finally figured out that I did not have default public constructor. My constructor was like here:
So lets move to adding icon of your UserControl to the Toolbox
1) First add your control and draw the icon. Below is screenshot of what I have for this.
a) Once you done, you should ensure that your control has public default constructor and that OnPaint method will not raise exceptions after it was called on instance created with default constructor.
b) Also go to properties of your icon and set Build Action –> Embedded Resource.
2) Add ToolboxBitmap attribute to your control class declaration. In my case it looks like below:
3) Navigate to ToolBox and add your control from your assembly:
That’s it!
January 26, 2010 QuickTip, UI, WindowsForms No comments
Do you want to see your button to be in pressed or unpressed state when you hit it once?
Did you catch that this behavior is not really button’s behavior – it is more checkBox’s behavior.
So to accomplish your goal you need move checkBox to your form and set appearance from “Normal” to “Button”. Like here:
Kick me if you don’t want to see such posts on my blog. :)