We help IT Professionals succeed at work.

Drawing a line on top of other components

Pandora
Pandora asked
on
Hullo all!  I have a panel that contains lots of panels buttons and other components, but I want to draw a thin line right over the top of them that remains on top (but does not effect the clickability etc of the components beneath it).  Can anybody help me as I have no idea how to do this?!  Many thanks, P.
Comment
Watch Question

Commented:
draw this line on onpaint event of form which contains this components
Commented:
In your OnPaint event, check the position of your form on the screen, get the desktop device context and draw on it, like so

var
  C: TCanvas;
begin
  C := TCanvas.Create;
  C.Handle := GetDC(0);
  try
    C.Rectangle etc etc
  finally
    ReleaseDC(0, DC.Handle);
    C.Handle := 0;
  end;
end;

Commented:
cubud why to use getdc(0) if you have a canvas property of the form.
listening...

Commented:
Because the form has its own canvas, but so does every TWinControl on the form.

If you draw on the form it will draw underneath the WinControls and over the top of the GraphicControls (try it).

If all of your controls are graphic controls then that is fine, otherwise you need to draw on DC 0

Author

Commented:
Thanks very much Cubud - this is great and works like a dream!  P. :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.