Take the 2-minute tour ×

I want to plot a function in a form without the forms background being visible. Created a TForm with TransparentColor set to True and TransParentColorValue set to clWhite. Just put a TImage on it, draw a function on a bitmap, assign it to the image, works great. There is one problem. I cannot click the form anymore. Any click on the form's caption and clientarea lead to a click in the underlying application. This is caused by setting TransparentColor to True. How can I prevent this "clicking-thru"?

Update I tried Sertac's suggestions and I got some remarkable results. I prepare the bitmap as follows:

   Bitmap.Canvas.Brush.Color := clFuchsia;
   Bitmap.Canvas.FillRect (Rect (0, 0, Bitmap.Width, Bitmap.Height));

When Color is set to clWhite and the Forms TransparentColorValue as well, the form is completely click-thru enabled.

Both set to clBlack, the form can be moved, but borders can't be resized and system buttons don't work

Both set to clFuchsia it behaves as a normal Form. Well, it works now but maybe someone got an explanation?

share|improve this question
Use a different color (I have no idea why..). –  Sertac Akyuz Apr 21 '12 at 14:05
Weird, setting the TransparentColorValue to clBlack and filling the bitmap with clBlack as well works partially. It doesn't click-thru, I can move the form now, but still cannot resize and the system buttons don't react. Any idea how to solve that? –  Arnold Apr 21 '12 at 14:17
Where do you find those colors? <g> Make it clFuchsia and let go.. :) –  Sertac Akyuz Apr 21 '12 at 14:20
This isn't VCL's fault by the way. I suggest you to include a litte snippet duplicating this with api calls and include winapi tag. –  Sertac Akyuz Apr 21 '12 at 14:27
You are not joking, it really works with the clFuchsia!!! Thank you! What exactly do you mean with api calls? If you answer this question I'll mark it as the correct one. –  Arnold Apr 21 '12 at 14:33
add comment

1 Answer

up vote 3 down vote accepted

It would seem the API acts weird when some specific colors is used. White is an obvious one, black is a little less problematic. I've tried with yellow, gray, button face, fuchsia etc.. and they look fine.

If anyone wants to duplicate the problem without using Delphi's 'Transparent...' properties, here's a little snippet:

procedure TForm1.Button1Click(Sender: TObject);
  Color: DWORD;
  DC: HDC;
  Color := $00FFFFFF;
  SetWindowLong(Handle, GWL_EXSTYLE,
      GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED );
  SetLayeredWindowAttributes(Handle, Color, 255, LWA_COLORKEY);

  DC := GetWindowDC(Handle);
  SetDCBrushColor(DC, Color);
  FillRect(DC, Rect(10, 10, 100, 80), GetStockObject(DC_BRUSH));
  ReleaseDC(Handle, DC);

Note: I'd gladly remove this answer if anyone provides an answer with a definitive explanation.

share|improve this answer
I agree with that. –  Arnold Apr 21 '12 at 14:55
add comment

Your Answer


