Toolbox Images no longer showing up transparent

For some reason the code that we used to use from 2003 for adding toolbox items with transparent images no longer works in 2005.  We are using the latest release of 2005 with the latest SDK.

Here is our code:

Bitmap bmp = new Bitmap(typeof(MyClassName), "Resources.mybitmap");
uint clrTransparent = (uint)Color.Fuchsia.ToArgb();

// Declare toolbox item structure
TBXITEMINFO[] tbxInfo;
tbxInfo =
new TBXITEMINFO[1];
tbxInfo[0].bstrText = "mytoolboxitem";
tbxInfo[0].hBmp = bmp.GetHbitmap();
tbxInfo[0].clrTransparent = clrTransparent ;
int result = svc.AddItem(dataObject, tbxInfo, BlackberryConstants.TabName);

The toolbox item adds just fine and our image does show up in the toolbox but the Fuchsia color that is in the bitmap is not converted to transparent.

We have tried doing a "SetTransparentColor" on the bitmap before passing it to the TBXITEMINFO but that causes even more wierd painting to occur

Anyone have some ideas on what may have been changed



Answer this question

Toolbox Images no longer showing up transparent

  • JayKay

    It was the combination of the two that worked.. Thanks guys... here is the working code:

    Bitmap bmp = new Bitmap(typeof(MdsFormEditorToolbox), "Resources." + resource);
    uint clrTransparent = (uint)System.Drawing.ColorTranslator.ToWin32(Color.Fuchsia);

    // Declare toolbox item structure
    TBXITEMINFO[] tbxInfo;
    tbxInfo =
    new TBXITEMINFO[1];
    tbxInfo[0].bstrText = name;
    tbxInfo[0].hBmp = System.Windows.Forms.
    ControlPaint.CreateHBitmap16Bit(bmp, Color.Fuchsia);
    tbxInfo[0].clrTransparent = clrTransparent ;
    int result = svc.AddItem(dataObject, tbxInfo, BlackberryConstants.TabName);


  • Henk van Andel

    Does it help if you use System.Windows.Forms.ControlPaint.CreateHBitmap16Bit instead of Bitmap.GetHBitmap

    -Josh
    VS Platform team

  • BarBQ

    I tried your suggestion and changed the line to:

    tbxInfo[0].hBmp = System.Windows.Forms.ControlPaint.CreateHBitmap16Bit(bmp, Color.Fuchsia);

    instead of:

    tbxInfo[0].hBmp = bmp.GetHbitmap();

    The result of this was that the Black areas of the bitmap became transparent and the Fuchsia stayed Fuchsia.

    I've been thinking along the same lines though, that it may have something to do with the color pallet...


  • Vaibhav_Patel

    I wonder if it's related to the way you're computing the transparent color.  Does it make any difference if you use System.Drawing.ColorTranslator.ToWin32 instead of Color.ToArgb

    -Josh
    VS Platform team

  • Toolbox Images no longer showing up transparent