473,418 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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

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
2 8704
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jean-dot-paul-at-opelwilly-dot-com | last post by:
Hello, Can I use the ToolboxBitmap from the inherted Control to show up in my toolbox and if so how? Greetings Jean Paul
1
by: Asha | last post by:
greetings, i need to upload an .xls file using a secure connection. so i though of using https... can i know how this can be done?
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
0
by: nicolas.hilaire | last post by:
Hi all, i'm creating an User Control (that is working). I would like to see my own image for this control, in the toolbox. Then, i'm using ToolboxBitmap namespace testUserControl { ...
1
by: rushikesh.joshi | last post by:
Hi All, I want some charting functionality in my ASP.NET application. I want to show a multiple bar on my web page. It's based on down time of different servers. like server1: down betn 4 AM...
0
by: John | last post by:
I've created a component in VS.NET 2003 and I'm having a hard time getting my bitmap to show up in the Designer Toolbox in Visual Studio. I have designed an .ico file and have included the...
3
by: Tony Johansson | last post by:
Hello! You can set target Module for AttributeUsage. I just wonder what does it mean with module ? //Tony
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.