Can't get <ToolboxBitmap> to work!

M

MyndPhlyp

(Second posting attempt)

I have been through tons of old postings, several web sites, books, and even
tried consulting a psychic but nothing is yielding the majik answer. I'm
using VB '05 Express on a Win2K system.

The project has everything grouped under various directories. The Solution
Explorer looks like...

AProject
--My Project
--classes
----AClass.vb
--forms
----AForm.vb
--Resources
----AClass.bmp

If you haven't guessed it already I am trying to get the AClass.bmp to be
the Toolbox icon for the AClass class rather than the default gear. The
class's abbreviated version looks like...

Namespace AProject
<ToolboxBitmap(GetType(AProject.AClass), "AClass")> _
Public Class AClass
Inherits System.Windows.Forms.TextBox
' Properties, Methods, and Events snipped
End Class
End Namespace

The bitmap is 15x15 16-color. (Documentation says 16x16, expert sites say
16x15 or 15x16 but don't bother to mention if that is height-by-width or
width-by-height so I took the lowest common denominator.) The Build Action
is set to Embedded Resource.

The file is listed in the Project's Resources and the Persistence is set to
Linked at compile time.

I've tried several permutations on the string value at the second parameter
position including...

AProject.Resources.AClass (w/ and w/o ".bmp")
Resources.AClass (w/ and w/o ".bmp")
AProject.AClass (w/ and w/o ".bmp")
AClass (w/ and w/o ".bmp")

I've tried relocating the BMP to the root directory of the Project and/or
the classes directory.

I've tried a fully-qualified path and file name.

I've tried everything except electroshock therapy and I'm seriously
considering even that option today.

What the heck am I doing wrong (other than wasting time on this very trivial
matter)?
 
M

MyndPhlyp

Mudhead said:
<ToolboxBitmap(GetType(AProject.AClass), "AProject.AClass.bmp")>

Thanks, Mudhead. (Still seeing Bottles?) Must be something to do with my
installation. It just isn't doing it for me.


[...This is a line of Indians leaving beautiful Rancho Malario-to make room
for YOU! Here's the beautiful Trail of Tears golf course...(click)...et's
talks about your car. It's screaming "Wash me, please!" Now, if you're a Mr.
Common Sense, you won't believe me when I tell you that I've got an envelope
that'll clean your car while you're driving it home to work. Well, George,
believe me this time, because this one isn't like the Austrian
self-sharpening razors. No, friends, no overheating like the tropical
fishes. No zizzing and dripping like with the dike...(click)...Hi! I'm Joe
Beets. Say, what chance does a returning deceased war veteran have for that
good-paying job, more sugar, and the free mule you've been dreaming of?
Well, think it over. Then take off your shoes. Now you can see how increased
spending opportunities mean harder work for everyone, and more of it, too!
So do your part today, Joe. Join with millions of your neighbors and turn in
your shoes! For INDUSTRY!]
 
M

Mudhead

Here's a funky solution. I had the same problem you did but I finally got it
to work on my machine. Here's how I did it.

Include a 16x16 bitmap and set Build Action to Embedded Resource.

Add this to your class and the compile.
<ToolboxBitmap(GetType(AClass), "AClass.bmp")> _

Once compiled, open up your Bitmap (from Solution Explorer) in MSPaint and
make it smaller like 10x10 and then save it. Recompile the project.

Open it up the Bitmap again and reset it to 16x16, save and then Recompile.
It should now show up when you load it into the IDE.

You might have to do this a couple of times making it bigger and then
smaller but eventually it will work. You might also try inverting the
picture (that seemed to help). I took me about 3 or 4 times before it
started to take. I can now add any bitmap (as an embedded resource) to my
projects and it works perfectly.

I have no idea why this works, it just does.


MyndPhlyp said:
Mudhead said:
<ToolboxBitmap(GetType(AProject.AClass), "AProject.AClass.bmp")>

Thanks, Mudhead. (Still seeing Bottles?) Must be something to do with my
installation. It just isn't doing it for me.


[...This is a line of Indians leaving beautiful Rancho Malario-to make
room
for YOU! Here's the beautiful Trail of Tears golf course...(click)...et's
talks about your car. It's screaming "Wash me, please!" Now, if you're a
Mr.
Common Sense, you won't believe me when I tell you that I've got an
envelope
that'll clean your car while you're driving it home to work. Well, George,
believe me this time, because this one isn't like the Austrian
self-sharpening razors. No, friends, no overheating like the tropical
fishes. No zizzing and dripping like with the dike...(click)...Hi! I'm Joe
Beets. Say, what chance does a returning deceased war veteran have for
that
good-paying job, more sugar, and the free mule you've been dreaming of?
Well, think it over. Then take off your shoes. Now you can see how
increased
spending opportunities mean harder work for everyone, and more of it, too!
So do your part today, Joe. Join with millions of your neighbors and turn
in
your shoes! For INDUSTRY!]
 
M

MyndPhlyp

Mudhead said:
Here's a funky solution. I had the same problem you did but I finally got it
to work on my machine. Here's how I did it.

Include a 16x16 bitmap and set Build Action to Embedded Resource.

Add this to your class and the compile.
<ToolboxBitmap(GetType(AClass), "AClass.bmp")> _

Once compiled, open up your Bitmap (from Solution Explorer) in MSPaint and
make it smaller like 10x10 and then save it. Recompile the project.

Open it up the Bitmap again and reset it to 16x16, save and then Recompile.
It should now show up when you load it into the IDE.

You might have to do this a couple of times making it bigger and then
smaller but eventually it will work. You might also try inverting the
picture (that seemed to help). I took me about 3 or 4 times before it
started to take. I can now add any bitmap (as an embedded resource) to my
projects and it works perfectly.

I have no idea why this works, it just does.

Hmm. The methodology hints fault lies in the Resources files (or the
construction/implementation thereof). Perhaps the order of the properties or
even the names of the properties (where the presence of a reserved word as a
property name is preventing some key critical thing from happening
correctly). Initial attempts at your suggestion haven't yet yielded the
desired result but I'll keep trying things to see what happens.

In the Resources, do you leave the Persistence at the default "Linked at
compile time" or do you change that to "Embedded in .resx"?

And on the BMP's properties, do you leave the Copy to Output Directory at
the default "Do not copy" or change it to "Copy always" or "Copy if newer"?
 
M

Mudhead

I can assure you that this works as described. Try this instead. Delete the
resource folder from the Soultion Explorer (make sure you have a copy of the
bitmap). Once it is deleted, right click on your projects name from the
Solutions Folder and Select Add Existing File. Add your Bitmap to the
project. It will show up simply as a Bitmap file (it won't be under a
resource folder). Set the build action of the Bitmap to embedded resource
and leave everything else the same. Add the <ToolboxBitmap(GetType(AClass),
"AClass.bmp")> _ to the top of your class. Then compile. Then do the
procedures that I described. I can show you a my test project if you want
to see it how it should look.
 
M

MyndPhlyp

Mudhead said:
I can assure you that this works as described. Try this instead. Delete the
resource folder from the Soultion Explorer (make sure you have a copy of the
bitmap). Once it is deleted, right click on your projects name from the
Solutions Folder and Select Add Existing File. Add your Bitmap to the
project. It will show up simply as a Bitmap file (it won't be under a
resource folder). Set the build action of the Bitmap to embedded resource
and leave everything else the same. Add the <ToolboxBitmap(GetType(AClass),
"AClass.bmp")> _ to the top of your class. Then compile. Then do the
procedures that I described. I can show you a my test project if you want
to see it how it should look.

It has to be something hosed with my installation then.

I created a new project, kept the default empty Form, added a Class named
DummyClass, added DummyClass.BMP (16x16, 16-color depth) to the Project
changing the Build Action to Embedded Resource, added
<ToolboxBitmap(GetType(DummyClass), "DummyClass.bmp")> to the Class
definition plus "Inherits System.Windows.Forms.RichTextBox" to the Class
body (so that it appears as an insertable object in the ToolBox). Everything
is defaulted (with the minor exceptions already noted). No Namespace
declarations or anything else. Saved everything, did a build, flipped back
to the empty Form to get the ToolBox display. No love. Scaled the BMP down
to 10x10, recompiled. Still no love. Rescaled back to 16x16 and recompiled.
Still no love. Did that a few times with no change in the results. Just for
grins, exited and restarted VB 2005 Express. No good. Tried resetting the
ToolBox. Still not doing it.

The funny thing (in a masochistic sort of way) is that everything else
appears to be working just fine. If the installation were blown I would
expect to see other symptoms raising their ugly head.

I'd appreciate looking at your test project. The email address is MyndPhlyp
at yahoo dot com.
 
M

Mudhead

I'll send it. When you scale the bitmap back up to 16x16 make sure you fill
it with a random color then invert the colors and save. Also, you said you
were using it in a Windows Form project? That's probably your problem. When
I do it that way, I get the gears also. You sould create a control dll and
test it in another form outside your project. Then it will show up.
 
M

MyndPhlyp

Mudhead said:
I'll send it. When you scale the bitmap back up to 16x16 make sure you fill
it with a random color then invert the colors and save. Also, you said you
were using it in a Windows Form project? That's probably your problem. When
I do it that way, I get the gears also. You sould create a control dll and
test it in another form outside your project. Then it will show up.

<???>test it in another form outside your project </???>

How does one do that without utilizing a Windows Form project? I suspect you
are actually saying that I should maintain the Class as a separate project,
which I normally do anyway.

This most recent dummy project was a deviation from the norm though taking a
"default path" approach of creating a single Form and a single Class within
the same Windows Application project.

Attempting to recreate your results, starting with my "default path" dummy
project, I did a File => Add => Existing Project to link your project into
my project. Had to Build => Rebuild Solution to get ResourceTest to show up
in the Toolbox. Still showing the gear in both Components sections of the
Toolbox. Resizing and inverting colors is having no effect (other than
keeping me busy).

I did notice that your bitmap uses 24-bit 16M colors as opposed to the
recommended 4-bit 16 colors I have seen at various "expert" web sites. Also
contrary to "expert" recommendations is that the bitmap's name does not
equal the Class's name.

<heavysigh />

I take your word for it that this stuff works for your installation but I am
going to give up trying to make it work at this end. I have already wasted
far too much time and effort (at both our ends) on this very trivial matter.
While it would be nice to use unique icons, I can get by without them.
Perhaps somewhere along the line somebody will identify where the bug lies
and the resolution. This isn't the first time (nor, I suspect, the last)
things from Seattle failed to work as advertised.

Thanks for your time and patience on this. Time for us to get back to doing
something productive.
 
G

Guest

This is probably not your situation but I have had trouble getting embedded
resources to work when I add a project, say project "A", to my current
solution then try to add an embedded resource to Project "A" when the
solution for the first project is open. I have to close the open project
then open Project "A" separately, add the embedded resource them recompile
Project "A". When I re-open my original solution, I then have the resource
in Project "A" available.
 
M

MyndPhlyp

Dennis said:
This is probably not your situation but I have had trouble getting embedded
resources to work when I add a project, say project "A", to my current
solution then try to add an embedded resource to Project "A" when the
solution for the first project is open. I have to close the open project
then open Project "A" separately, add the embedded resource them recompile
Project "A". When I re-open my original solution, I then have the resource
in Project "A" available.

Yeah, that's an ongoing "theme" with this IDE. The easiest way I've found
around that is to go ahead and add in all the various projects of interest,
make sure the main project is the Startup Project, do a Build => Clean
Solution, and a Build => Rebuild Solution (the latter of which could
probably just as well be a Build => Build Solution).

The Clean removes any existing embeddable components from the Toolbox. The
Rebuild/Build puts them right back plus whatever was missing due to new
project inclusions. Once things have been rebuilt the objects are readily
available.

It is very annoying, to say the least. I am used to VB6 where I could toss
together a UC and immediately have it available for inclusion. With this IDE
a Build has to be done before the object becomes available even though you
are not generating a DLL or OCX.

Another annoyance in getting homegrown objects to embed is that the object's
qualifiers (namespace paths) tend to get messed up in the *.Designer.VB
files. Haven't found a solution to that one yet. I end up having to manually
fix them.

That is by far not an all-inclusive list however. Since I started down the
VB.Net path I have discovered /*many*/ 4-lettered words even God has never
heard before.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top