By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Using the System.Drawing.ToolboxBitmap attribute in VB.NET

P: n/a
I am attempting to create icons for controls I have created using VB.NET by
using the System.Drawing.ToolboxBitmap attribute. I have managed to do this
in C# by specifying the path to the *.ico file, but I have been unable to
get any of the overloads to work in VB.NET. I would like to store the *.ico
files in a *.resx file so that users do not need anything other than the
*.dll, but at the moment I am just trying to get any of the overloads of
System.Drawing.ToolboxBitmap to work in VB.NET. Here is my code and
directories (obviously not all files are listed, but I think these are the
ones of significance):

NateCtrl2005 (this is the name of my project)
My Project
Resources.resx (this is the resources file with my *.ico files)
ToolboxIcons (folder where I am storing the *.ico files)
ConditionalRequiredTextValidator.ico (Build Action=Embedded
Resource)
ConditionalRequiredTextValidator.vb
Code in ConditionalRequiredTextValidator.vb:

Namespace NathanSokalski
<System.Drawing.ToolboxBitmap("C:\Inetpub\wwwroot\ NateCtrl2005\ToolboxIcons\ConditionalRequiredTextV alidator.ico")>
Public Class ConditionalRequiredTextValidator
Nov 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I have tried that, but I can't get that to work either.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Fred" <fo*****@free.fr.invalidwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
in news:%2****************@TK2MSFTNGP03.phx.gbl, Nathan Sokalski wrote :
>I am attempting to create icons for controls I have created using
VB.NET by using the System.Drawing.ToolboxBitmap attribute.

In VB.NET, I just add a bmp file to the project and select «Embedded
Resource» in the «Build Action» property.

Then I use the third new (Type, String) of the TooboxBitmapAttribute.

--
Fred
fo*****@free.fr

Nov 3 '08 #2

P: n/a
MSDN http://msdn.microsoft.com/en-us/libr...0a(VS.80).aspx

The following I picked up on the web but do not remember where

Setting Toolbox Bitmaps
By default, icons that you make display a little gear in the control
toolbox. It's a cute icon, but it would- n't be very informative if you have
dozens of controls that all display the same icon, particularly if you don't
use the toolbox's list view so the icons and tooltips are the only tools you
have for finding the controls you want.
Unfortunately, setting a control's toolbox bitmap is rather tricky. To set
the bitmap, you add a Toolbox Bitmap attribute to the control's class. This
attribute has a couple of different constructors. The simplest gives the
complete path to the control's 16_16-pixel bitmap file. The following code
shows this type of attribute for the StyledListBox control:
<ToolboxBitmap("C:\StyledListBox\Resources\tbxStyl edListBox.bmp")_
Public Class StyledListBox
...
This version of the ToolboxBitmap attribute is simple and reliable.
Unfortunately, it ties the code to a specific location. If you later move
the toolbox bitmap, the statement no longer works.
To avoid this problem, you can just leave the control and its files in the
location where you initially build them. Another solution is to place all of
your toolbox bitmaps in a directory somewhere and never move them. These
solutions work, but restrict what you can do with the control's project. For
example, if you email the project to someone else, they must modify the
attribute's constructor so it can find the bitmap on the new computer.
Another constructor provided by the ToolboxBitmap attribute takes as
parameters the type of a class contained in an assembly, and then the name
of a bitmap resource in that assembly. The following code shows this version
of the attribute for the StyledListBox control:
<ToolboxBitmap(GetType(StyledListBox), "tbxStyledListBox")_
Public Class StyledListBox
...
This code tells Visual Basic to look in the assembly containing the
StyledListBox class for the resource named tbxStyledListBox.
In theory, this is a nice solution that lets the attribute find the bitmap
resource even if you move the project. In practice, getting this to work can
be tricky.
First, add a 16_16-pixel bitmap resource to the project and draw the image
you want to display in the toolbox. Next, select the bitmap file in the
Solution Explorer. In the Properties window, set the bitmap's Build Action
property to Embedded Resource.
If all goes well, the control will get the correct toolbox bitmap.
Unfortunately, if there's any kind of problem (for example, if Visual Basic
cannot find the file or the class), you won't see an error message and the
control gets the default gear icon.
If you change the control's icon and still see the wrong icon in the
toolbox, click the control in the tool- box, press the Delete key, and
confirm that you want to remove the control from the toolbox. Next, right-
click the toolbox and select Choose Items. Click the Browse button and find
the compiled control's DLL or EXE file. When you select the file and click
Open, the dialog adds the controls contained in that file to its list and
selects them. Click the control's entry to preview its toolbox bitmap. If
you see the gear bitmap (which you may be getting sick of by this point),
click Cancel so you don't add the control to the toolbox (so you don't have
to remove it again) and try again.

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I am attempting to create icons for controls I have created using VB.NET by
using the System.Drawing.ToolboxBitmap attribute. I have managed to do this
in C# by specifying the path to the *.ico file, but I have been unable to
get any of the overloads to work in VB.NET. I would like to store the *.ico
files in a *.resx file so that users do not need anything other than the
*.dll, but at the moment I am just trying to get any of the overloads of
System.Drawing.ToolboxBitmap to work in VB.NET. Here is my code and
directories (obviously not all files are listed, but I think these are the
ones of significance):

NateCtrl2005 (this is the name of my project)
My Project
Resources.resx (this is the resources file with my *.ico files)
ToolboxIcons (folder where I am storing the *.ico files)
ConditionalRequiredTextValidator.ico (Build Action=Embedded
Resource)
ConditionalRequiredTextValidator.vb
Code in ConditionalRequiredTextValidator.vb:

Namespace NathanSokalski

<System.Drawing.ToolboxBitmap("C:\Inetpub\wwwroot\ NateCtrl2005\ToolboxIcons\ConditionalRequiredTextV alidator.ico")>
Public Class ConditionalRequiredTextValidator
.
End Class
End Namespace
I have tried all three overloads of System.Drawing.ToolboxBitmap, and
could not get any of them to work. I have heard stuff about them not all
working correctly in VB.NET, but even in C# I was only able to get the one
where the path of the *.ico is specified to work. I think that Visual
Studio should have some kind of attribute editor or something (it lets you
use the Property Grid to set the Category and Default Value for
properties, and several things for the class, but not this one or many of
the others). If someone could help me I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 4 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.