Results 1 to 6 of 6

Thread: Age old Alpha Channel on Toolbar problem [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    Age old Alpha Channel on Toolbar problem [RESOLVED]

    Hey All,

    When you put Icons (.ICO) files into an Imagelist and then use that imagelist on a VB.NET toolbar the Alpha channel is lost, creating an ugly black border.

    MS has identified this as an error and said "too f-ing bad". Has anyone come up with a decent workaround?

    Thanks!

    --Ben
    Last edited by BenFinkel; Dec 1st, 2004 at 09:16 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Go to codeproject.com , and use one of the toolbar controls there. I've seen one that supports alpha channel and looks great with extra functionalities (It's in C# though) .

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    I've resolved the issue. It wasn't easy, but I'm going to post the details here in the hope that anyone else who stumbles across this post researching the same issue doesn't have to go through what I went through. It's not that hard to do once it's all together.

    1: Create a Manifest. It's just a text file, don't be scared
    2: Single out your icon in it's own file
    3: Add the icon by handle at runtime


    Step #1: Get a Manifest for XP-Style Controls

    A manifest tells your software to use the XP-version of controls instead of old ugly 95/98/2000 style. This applies to combo boxes, command buttons, radio buttons, etc... You can switch between XP-Style and Old-School-Ugly by using the 'FlatStyle' property.

    The Manifest is a text file, containing the following text (go ahead, cut and paste, it doesn't need to change at all) and be named <ExecutableName>.exe.manifest and be located in the same directory as the executable. You won't see the graphical changes in the IDE, but when the app runs it will look much nicer.

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity 
    version="1.0.0.0" 
    processorArchitecture="X86" 
    name="WindowsXP" 
    type="win32" 
    />
    <description>Your application description here.</description>
    <dependency>
    <dependentAssembly>
    <assemblyIdentity 
    type="win32" 
    name="Microsoft.Windows.Common-Controls" 
    version="6.0.0.0" 
    processorArchitecture="X86" 
    publicKeyToken="6595b64144ccf1df" 
    language="*" 
    />
    </dependentAssembly>
    </dependency>
    </assembly>
    Step #2: Make sure that the Icon size you want is the only icon size in the .ico file

    I haven't found a solution for this yet, so I had to strip the 16x16 versions of my Icons into their own .ICO file. If you don't, I'm not sure if you can know which size it will use.


    Step #3: Don't load the icons into the Imagelist until RUNTIME. One example I found loaded all of the .ICO files as embedded resources in the project at design time, and then loaded from that. I'm loading them into the Imagelist straight from the file at runtime. Either way will work. See the code below:

    Code:
    'In the Form Load Procedure
    'Create a Icon object
    Dim icoTemp AS System.Drawing.Icon
    
    'Load the Icon file
    icoTemp = New System.Drawing.Icon("C:\Icons\MyCoolIcon.ico")
    
    'If the ico file is an embedded resource
    'icoTemp = new & _ 
    System.Drawing.Icon( & _ 
    System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( & _
    "WindowsApplication1.EmbeddedReSource.ico"))
    
    'Add the Icon to the Imagelist control.
    'We do this by handle because it retains the Alpha Channel information this way
    Me.imlIcons.Images.Add(System.Drawing.Icon.FromHandle(icoTemp.Handle))
    
    'Finally, stick the Imagelist into our toolbar.  
    'I've already created the buttons and assigned their 
    'ImageIndex during design time, but this can be done anytime.
    Me.tlbMain.ImageList = imlIcons
    And that's it. It works for me (and works nicely I might add). Please feel free to email me with any questions ya got.


    --Ben

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Nice share . I'm gonna need it soon .Thanks buddy.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    Re: Age old Alpha Channel on Toolbar problem [RESOLVED]

    Side note,

    needed the same solution for the ListView icon.

    --Ben

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    Re: Age old Alpha Channel on Toolbar problem [RESOLVED]

    Another addendum:

    I fingered out how to make the changes show up in the VS.NET IDE. You need to use the manifest on the IDE's executable. Rename the manifest to "devenv.exe.manifest" and save it in the following folder: C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE


    --Ben

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width