Control transparency - temporary bmp

Posted on 2004-11-09
Last Modified: 2008-02-01
I'm trying to make my hexagon color picker XP
compatible, but since I'm drawing to a bmp and then using canvas.draw -
the parent background isn't painted (gets overpainted), and if I use
bmp.transparent the thing is tooo slow and flickery. I tried
DrawParentBackGround(Handle, bmp.canvas.handle, nil, false), but
nothing happends. What should I do, it looks terrible with WinXP (at least on a TTabControl)?

You can take a look at the screenshot at:

Any help GREATLY appreciated!!!
Question by:Bindza

    Expert Comment

    Hi bindza,
    as far as I remember, the transparent color It the color of the Lower-left pixel.
    When you draw the bmp, set the lower left pixel to the needed color (I your case, parent color).


    Author Comment

    You didn't understand, if I use bmp.transparent and the thing is resized there's unbearable flickering and very very bad system performance. Also, I can fill the bmp with the parent's color, but then I will end up with a solid back, but what if the parent is gradient - take a look at the screenshot - TTabSheet with XPMan. The bottom line is: the painting procedure doesn't touch the back, it only draws the haxagons, so I think I should either find a super-fast way to make bmp back transparent or draw the parent back onto the bmp before the hexagons are drawn (i tried with ThemeServices.DrawParentBackground, but didn't get anything painted).
    LVL 14

    Expert Comment

    erm... try capturing a Rect of the Parent's background first, then draw whatever you want on it and finally blt it back to the parent?

    Author Comment

    Can you give me some code, I don't know hot to "capture a Rect of the parent's background", I did think of it, but didn't know exactly how to do it.

    [What do you mean by "blt it back to the parent"? I've got my component and all I wanna do is draw a parent background to a bmp, then draw the control over it and put it onto the screen via canvas.draw, I'm not trying to draw onto the parent...]

    Author Comment

    Never mind, a friend helped me solve it, here it is:

    uses Themes;

    procedure TLColorPicker.PaintParentBack;
     OffScreen: TBitmap;
     MemDC: HDC;
     Offscreen := TBitmap.Create;
      Offscreen.Width := Width;
      Offscreen.Height := Height;
      Offscreen.Canvas.Brush.Color := Color;
      if ParentBackground then
       with ThemeServices do
        if ThemesEnabled then
          MemDC := CreateCompatibleDC(0);
          OldBMP := SelectObject(MemDC, OffScreen.Handle);
          DrawParentBackground(Handle, MemDC, nil, False);
          if OldBMP <> 0 then SelectObject(MemDC, OldBMP);
          if MemDC <> 0 then DeleteDC(MemDC);
      Canvas.Draw(0, 0, Offscreen);

    Accepted Solution

    Question PAQ'd
    250 points refunded.

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now