How do you use a a single bitmap that contains several separate images in a toolbar button? I assume that a
image list is needed but how do you tell it which area to use, etc. ? Do I have to parse out the images as
separate images altogether?
Thanks
Printable View
How do you use a a single bitmap that contains several separate images in a toolbar button? I assume that a
image list is needed but how do you tell it which area to use, etc. ? Do I have to parse out the images as
separate images altogether?
Thanks
Bitmap removed in order to stay within licensing terms. :(
You can use the AddStrip() method of an image list (you have to use one indeed):
and then you can assign the image index to one of your buttons.VB Code:
ImageList1.Images.AddStrip(New System.Windows.Forms.PictureBox().Image.FromFile("C:\216.gif"))
:confused: Weird thing is that you never specify the number of images in the image strip - but AddStrip() figures it out anyway. :confused:
It probably assumes that all the icons are square and not rectangular, thus its Length / height to find out how many icons are present.
The ImageList has an ImageSize property the Width of which is used to calculate the breaking up of the strip.
Doh! .AddStrip, so simple. I assumed that they did it in code instead of a built in function of the IL.Quote:
Originally Posted by ntg
I'll try it out, but I'll assume (again) that its straight forward and simple. :lol:
Thanks guys :thumb:
Why cant anything be straight forward????
I added the strip as a embedded resource. Then I tried to .AddStrip of the GetType() for the resource, but its
generating an exception on that line. :(
I even tried manually adding the strip to the IL but it doesnt show up on the button.VB Code:
Me.ImageList1.Images.AddStrip(New Bitmap(Me.GetType(), "24OffLarge-214.bmp")) tbbNavigation.Buttons.Item(5).ImageIndex = 0
Shot in the dark rob, the resource identifier string ("24OffLarge-214.bmp") is CaSe sensitive. Might be worth checking. :)
I think the issue is the image. The resource editor says it cant be viewed since it contains more the 256 colors,
but it is loaded correctly.
I changed images to an ico file and it didnt error but it didnt show up either. So I turned off the VisualStyles and the ico image now shows. :(
How do I get the toolbar to draw images while running VisualStyles?
I'm a noob and guessing, but did you try to change the Colour Depth property on the ImageList before you resorted to changing the images to *.ico? Its worth a try ;)
Yes, I have the imagelist set to 32 bit in the properties window at design time.
I just resized the IL to match the image strip and I get an error that its too wide - 1128, 256 max. :(
What can I do? Guess I'll have to slice up the strip into individule pixs?
VB Code:
Me.ImageList1.ColorDepth = ColorDepth.Depth32Bit Me.ImageList1.ImageSize = New Size(1128, 24) Dim img As New Bitmap(Me.GetType(), "24OffLarge-214.bmp") Me.ImageList1.Images.AddStrip(img) tbbNavigation.Buttons.Item(5).ImageIndex = 1
Hi,
No need to slice - it works fine for me without the gettype. The imagesize property of the imagelist needs to be the size of the individual images - the imagelist automatically calculates how many there are by dividing up the strip. If your strip is 32x16 pixels and you set the image size to be 16x16, even M$ can figure out how many images there are there.
If instead of your Me.Gettype, you just hardcode in the filename and set the image size to be 16x16 (or whatever) then it'll work. Your problem is not with the method, it's the embedding bit.
HTH
zaza
Yes, I have two issues, embedding and adding. I looked all through the help files and there is only one small page on .AddStrip. No
where did it say to set the width to the individule pixs but that makes 100% sense. I will test it out.
I need the GetType since I need my files to be embedded resources and not be located on the fs.
Thanks zaza I will post back. :)
Ok, got the strip added and images associated with each button.
Two things:
1. Doesnt draw on the VisualStyle layer.
2. The black area is displayed. Probably needs a mask or transparency color designated.
VB Code:
Me.ImageList1.ColorDepth = ColorDepth.Depth32Bit Me.ImageList1.ImageSize = New Size(24, 24) Dim asm As Reflection.Assembly = Me.GetType().Assembly() Dim img As New Bitmap(asm.GetManifestResourceStream("24OffLarge-214.BMP")) Me.ImageList1.Images.AddStrip(img)
This is a shot of it without the visual styles applied. If I turn on the vs then the vs draws over the layer that the
arrows are drawn on. The vs are drawn on a different top level layer.
Any ideas on how to draw on the theme layer and eliminate the black?
Got a little farther. I found the .TransparentColor property of the imagelist, Doh!
Now still need to draw on the visualstyle layer and is there a way to make the images smoother, less jaggie?VB Code:
Me.ImageList1.TransparentColor = Color.Black
If I cant get this solved for the strip then I'm going to have to find another way to create the images with smoothing effects. :(
As for the drawing on the visual style layer, I found some Theme APIs that may do the trick but I think thats a new thread.
Rob, try investigate in how to apply a blur onto the images. In VB6 I remember an effect that I saw in an example which would blur an image by a specified value. That would make the images smoother.
Wouldnt that blur the entire image? I know there is AntiAliasing for text, I'm hoping there is something similar to your suggestion.
I'll try a look. Thanks.