Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the canvas behind my component?

174 views
Skip to first unread message

Wayne Fulcher

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
Lets assume I am writing a TPanel component.
What is the best way to get a copy of the canvas behind where my component
would be?
Keep in mind the Parent property may point to a TForm, another TPanel or any
other component
that is a container component.

I am also thinking that if there is a way to capture the entire screen to a
canvas (Like a printscreen function would probably do) then I could use
screentoclient() and clienttoscreen() methods to copy my rect out of that.

Thanks
Wayne Fulcher
Digital Dimensions, Inc.
wa...@ddinet.com
706-869-9993

Paul Chapman

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
I am almost certain somebody will come up with a one stop solution to this,
but in the meantime, you could try the following (longwinded) way of
doing this...

In this example a Button will be sitting on top of a Panel, and we are
getting the bitmap
which the button will obscure.

Get the Buttons parent, ie the Panel, which will be a TWinControl.
Create a bitmap the same size as the Button.
Paint the win control to the bitmap, using
PaintTo(newBitmap.Canvas.Handle, -Button1.Left, -Button1.Top).

Code will look something like this (not tested...)

function getScreenAreaBehind(aComponent :TComponent) :TBitmap;
var
container :TWinControl;
bitmap :TBitmap;
begin
container := aComponent.parent;
bitmap := TBitmap.create;
with bitmap do
begin
width := Button1.width;
height := button1.height;
end;


container.PaintTo(bitmap.canvas.handle, -aComponent.Left, -aComponent.Top);
result := bitmap;
end;

Wayne Fulcher wrote in message <7123pq$72...@forums.borland.com>...

Doug Kurtz

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
Get the Device Context for Parent/WinControl of your component. This
Parent/WinControl may or may not have a Canvas property but will have a Device
Context. Use the Device Context of the Parent.

Peter Below

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
> Lets assume I am writing a TPanel component.
> What is the best way to get a copy of the canvas behind where my component
> would be?

There is nothing behind your component <g>. At runtime the components on a
form are all created before the form is shown, so when the parent of your
control proceeds to paint itself the first time it will not bother to paint
the part covered by your component (since it has the WS_CLIPCHILDREN window
style). The only option you have is to make your control invisible, then use
Pauls PaintTo trick and finally make your control visible again.

Peter Below (TeamB) 10011...@compuserve.com)


0 new messages