toolboxbitmapattribute

  • Thread starter Thread starter plmanikandan
  • Start date Start date
P

plmanikandan

Hi,
I need to provide bitmap to my user control.If the bitmap is
available,then use that bitmap ,else use the standard image of control
For example i'm creating a customized button(mybutton)

[ToolboxBitmap(typeof(Button),"test.ico")]
public class MyButton : System.Windows.Forms.Button

I made the test.ico as embedded resource.From the above ToolboxBitmap
attribute,if test.ico
found in local path it is used as toolbar image,else the image of
button.Is my understanding correct or not?
I'm not getting the image for MyButton using the above coding.Kindly
help me to solve the pbl

Thanks & regards,
Manikandan
 
Hi,
I need to provide bitmap to my user control.If the bitmap is
available,then use that bitmap ,else use the standard image of control
For example i'm creating a customized button(mybutton)

[ToolboxBitmap(typeof(Button),"test.ico")]
public class MyButton : System.Windows.Forms.Button

I made the test.ico as embedded resource.From the above ToolboxBitmap
attribute,if test.ico
found in local path it is used as toolbar image,else the image of
button.Is my understanding correct or not?
I'm not getting the image for MyButton using the above coding.Kindly
help me to solve the pbl

The first argument (type) specifies the defining assembly searched for the
bitmap resource. Since you specified Button, it's looking in
System.Windows.Forms, not your assembly as intended. Instead use:

[ToolboxBitmap(typeof(MyButton),"test.ico")]

In addition, test.ico must be in the root folder of your project. If you
have it in a subfolder, e.g. "art", you need to add that to the path with a
period, such as:

[ToolboxBitmap(typeof(Button),"art.test.ico")]

Also make sure that your icon (or bitmap) is 16x16 with 16 colors.
 
Hi,
Thanks for your reply.Suppose the bitmap file is available user control
has to use that as toolboxbitmap image,if bitmap file is not available
then it has to use standard button image.Is it possible to achieve this
using ToolboxBitmap attribute


Thanks & Regards,
Manikandan
Mini-Tools Timm said:
Hi,
I need to provide bitmap to my user control.If the bitmap is
available,then use that bitmap ,else use the standard image of control
For example i'm creating a customized button(mybutton)

[ToolboxBitmap(typeof(Button),"test.ico")]
public class MyButton : System.Windows.Forms.Button

I made the test.ico as embedded resource.From the above ToolboxBitmap
attribute,if test.ico
found in local path it is used as toolbar image,else the image of
button.Is my understanding correct or not?
I'm not getting the image for MyButton using the above coding.Kindly
help me to solve the pbl

The first argument (type) specifies the defining assembly searched for the
bitmap resource. Since you specified Button, it's looking in
System.Windows.Forms, not your assembly as intended. Instead use:

[ToolboxBitmap(typeof(MyButton),"test.ico")]

In addition, test.ico must be in the root folder of your project. If you
have it in a subfolder, e.g. "art", you need to add that to the path with a
period, such as:

[ToolboxBitmap(typeof(Button),"art.test.ico")]

Also make sure that your icon (or bitmap) is 16x16 with 16 colors.

--
Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com
 
Hi,
Thanks for your reply.Suppose the bitmap file is available user control
has to use that as toolboxbitmap image,if bitmap file is not available
then it has to use standard button image.Is it possible to achieve this
using ToolboxBitmap attribute

I am not aware of such a feature. Besides, you should know at compile time
if the bitmap is available just by testing it, so this feature is not really
necessary anyway.

BTW, here is a free tool (with C# source code) that you can use to add your
custom control to the Visual Studio Toolbox:

http://www.mini-tools.com/downloads/index.htm#vsinstaller
 
Back
Top