Toggle button with icon

molemenacer

Active member
Joined
Jul 27, 2006
Messages
27
Location
Haywards Heath, UK
Programming Experience
Beginner
Hi all,

I'm trying to display an icon on a toggle button with text, but the image won't show. I am trying to show the image by loading it into an image list and then referencing it.

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] ImgList [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ImageList
[/SIZE][SIZE=2]ImgList = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ImageList
ImgList.Images.Add( LoadIcon("Play.ico") )
[/SIZE]

That is my imglist - with about 8 icons

VB.NET:
[SIZE=2]
chkAvailability.Image = ImgList.Images( 0 )
[/SIZE]

And i am trying the above code to display an image - it dosen't seem to work.

Any help would be appreciated.

Thanks
 
Doesn't seem to work how? An exception? no image being displayed? I take it LoadIcon is a sub you have created? Could you show the code for that as well?
 
The image is not displayed.

This is the code for the loadicon

VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] LoadIcon( [/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] strIdentifier [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]Optional[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] bShared [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2] ) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Drawing.Image[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] stream [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.Stream = LoadResource( strIdentifier, bShared )[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] reader [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.StreamReader = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.IO.StreamReader( stream )[/SIZE]
[SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Drawing.Icon( reader.BaseStream ).ToBitmap()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]

Is there an easier way to accomplish this without using this method
 
Last edited:
Thanks for taking an interest vis781, but i have solved the problem.

If the Flatstyle of the button is set to system the image doesn't show, however when i set it to standard it worked fine and i could see the image.

Thanks anyway.
 
Back
Top