[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • Last Modified:

Control transparency - temporary bmp

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: http://mxs.topcities.com/hexa.png

Any help GREATLY appreciated!!!
1 Solution
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).

BindzaAuthor Commented:
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).
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?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

BindzaAuthor Commented:
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...]
BindzaAuthor Commented:
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);
Question PAQ'd
250 points refunded.

Community Support Moderator

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now