Solved: transparent bitmaps in add-in toolwindows of VS 2010 (Beta 1)

In the previous post I explained how to get transparent bitmaps for add-in commands in VS 2010 Beta 1 and previous versions. Now it is the turn of toolwindow bitmaps. Again, if you have a .NET 2.0 add-in that uses XML registration and a managed
satellite DLL and targets VS 2005, 2008 and 2010 Beta 1, the situation is as
follows:

1) Toolwindow bitmaps for VS 2005:

  • Use either:
    • A 32-bit bitmap with transparency in the alpha channel.
    • A 24-bit bitmap with RGB=255,0,255 (magenta) as transparent color
  • Call EnvDTE.Window.SetTabPicture(bitmap.GetHbitmap) (for some reason passing bitmap.GetHbitmap().ToInt32 causes System.ArgumentException: Value does not fall within the expected range)
  • Call EnvDTE.Window.Visible = True (this must be done after setting the toolwindow picture)

2) Toolwindow bitmaps for VS 2008:

  • Use either:
    • A 32-bit bitmap with transparency in the alpha channel.
    • If the color depth of the screen is:
      • 16-bit, you can use a 24-bit bitmap with RGB=0,254,0 (almost pure green) or a 24-bit bitmap with RGB=255,0,255 (magenta) as transparent color
      • 24-bit: I couldn’t test this case on my computers.
      • 32-bit: you need to make the bitmap transparent calling bitmap.MakeTransparent(<background color>).
  • Call EnvDTE.Window.SetTabPicture(bitmap.GetHbitmap().ToInt32()) (for some reason passing just bitmap.GetHbitmap causes System.ArgumentException. You need to convert the IntPtr to integer)
  • Call EnvDTE.Window.Visible = True (this must be done after setting the toolwindow picture)

3) Toolwindow bitmaps for VS 2010 Beta 1:

Bottom line: if the bug mentioned above with VS 2010 and 32-bit bitmap with transparency in the alpha channel is fixed for VS 2010 final release (Update, August 6: VS 2010 Beta 2 will fix it), you will be able to use 32-bit bitmap with transparency in the alpha channel in the three VS versions, but taking into account that sometimes you need to use the IntPtr value returned by GetHBitmap, and others its Int32 value.

I hope the information above is accurate because it is really messing to test all cases. Let me know if you can corroborate or not.

2 thoughts on “Solved: transparent bitmaps in add-in toolwindows of VS 2010 (Beta 1)”

  1. Hi Carlos,
    Thanks for providing the solution to transparent tool window bitmaps for VS Add-ins. I am working on an Add-in which is targeting all versions of Visual Studio (VS 2005,2008 and 2010). I used the same approach you mentioned for setting up icon for tool windows. However, I am getting the same error (tool window picture shows transparency when window is focused, it doesn’t when tool window is not focus). My Add-in is behaving in this way for all three versions of Visual Studio rather than just VS 2010.

    I have used a 32 bit bitmap of size 16*16 with alpha transparency color to set the icon for tool window. I am adding this icon as resources in the dll, and then creating an image from stream for the icon, and then creating a Bitmap for the icon as following:

    Assembly asm = Assembly.GetExecutingAssembly();
    Image img = Image.FromStream(asm.GetManifestResourceStream(Constants.ICON_ID));
    Bitmap bmp = new Bitmap(img);

    once I get the bitmap, I use the following code to assign image to tool windows:

    try
    {
    EnvDTE.Window.SetTabPicture(bitmap.GetHbitmap)
    }
    catch
    {
    EnvDTE.Window.SetTabPicture(bitmap.GetHbitmap().ToInt32())
    }

    I have used the try catch block to make sure that icon is created for all three versions of Visual studio.

    But still tool window picture is not coming as transparent when not focused for VS 2005,2008 and 2010

    Please let me know how to resolve this issue.

    Thanks & regards,
    Manjeet Singh

  2. Manjeet,

    Can you use the second approach, that is, the 24-bit bitmaps with magenta for VS 2005 and 2010 and bitmap.MakeTransparent() for VS 2008? This is what I am using and it works.

Comments are closed.