Board index » delphi » Repainting graphics covered by another window, how?

Repainting graphics covered by another window, how?

This is regarding Delphi 2.0 under Win95/WinNT:

I have probably not understood how Delphi handles repaints of canvas
graphics, so if anybody cares to explain I would be very happy:

I used to program in VB, there I could set a repaint property to
"automatic" for a picture. This caused the picture to reappear after it
had been covered by another window and display all info drawn there.
Nothing was lost, it seems like Windows itself or some internal working of
the control kept track of what was inside the drawing area.

In Delphi I cannot get this to work. I have yet to find the automatic
repaint property.
I have made an app that contains a graphics window (PictureBox) onto which
I draw lines and circles in order to map some incoming data values. As
soon as one part of the graphics has been covered by another window its
contents disappears permanently when the cover is removed!
What can I do to get it back?

I have read about an event called OnPaint in which I am supposed to
repaint the picture, but I don't anymore have access to all the data that
have been plotted to the canvas. (It was passing through the program on
its way elsewhere.)
Must I keep a memory copy of the canvas to restore the picture from when
there is an OnPaint event and in such case how can I draw to such a
"memory canvas"?
Or is there a property I have not found?

Please someone help out....

--------------------------------------------------------
Bo Berglund

(please e-mail to: bo.bergl...@mailbox.swipnet.se)

 

Re:Repainting graphics covered by another window, how?


Quote
bo.bergl...@mailbox.swipnet.se (Bo Berglund) wrote:
>This is regarding Delphi 2.0 under Win95/WinNT:
>I have probably not understood how Delphi handles repaints of canvas
>graphics, so if anybody cares to explain I would be very happy:
>I used to program in VB, there I could set a repaint property to
>"automatic" for a picture. This caused the picture to reappear after it
>had been covered by another window and display all info drawn there.
>Nothing was lost, it seems like Windows itself or some internal working of
>the control kept track of what was inside the drawing area.
>In Delphi I cannot get this to work. I have yet to find the automatic
>repaint property.
>I have made an app that contains a graphics window (PictureBox) onto which
>I draw lines and circles in order to map some incoming data values. As
>soon as one part of the graphics has been covered by another window its
>contents disappears permanently when the cover is removed!
>What can I do to get it back?
>I have read about an event called OnPaint in which I am supposed to
>repaint the picture, but I don't anymore have access to all the data that
>have been plotted to the canvas. (It was passing through the program on
>its way elsewhere.)
>Must I keep a memory copy of the canvas to restore the picture from when
>there is an OnPaint event and in such case how can I draw to such a
>"memory canvas"?
>Or is there a property I have not found?
>Please someone help out....

You need to draw into something that stores images.  Drawing onto the
screen, or into a window canvas is always a transitory action.  Any
other drawing operation (by any app) to that same area will overwrite
your work.

TBitmap stores images.  TImage displays bitmaps.  Drop a TImage on
your form, and draw on the Image1.Bitmap.Canvas.

-Danny

Re:Repainting graphics covered by another window, how?


Quote
Bo Berglund wrote:

> This is regarding Delphi 2.0 under Win95/WinNT:

> I have probably not understood how Delphi handles repaints of canvas
> graphics, so if anybody cares to explain I would be very happy:

> I used to program in VB, there I could set a repaint property to
> "automatic" for a picture. This caused the picture to reappear after it
> had been covered by another window and display all info drawn there.
> Nothing was lost, it seems like Windows itself or some internal working of
> the control kept track of what was inside the drawing area.

> In Delphi I cannot get this to work. I have yet to find the automatic
> repaint property.
> I have made an app that contains a graphics window (PictureBox) onto which
> I draw lines and circles in order to map some incoming data values. As
> soon as one part of the graphics has been covered by another window its
> contents disappears permanently when the cover is removed!
> What can I do to get it back?

> I have read about an event called OnPaint in which I am supposed to
> repaint the picture, but I don't anymore have access to all the data that
> have been plotted to the canvas. (It was passing through the program on
> its way elsewhere.)
> Must I keep a memory copy of the canvas to restore the picture from when
> there is an OnPaint event and in such case how can I draw to such a
> "memory canvas"?
> Or is there a property I have not found?

> Please someone help out....

> --------------------------------------------------------
> Bo Berglund

> (please e-mail to: bo.bergl...@mailbox.swipnet.se)

Because you don't have anymore the access to the needed data, the
following is the right thing to do, I think:

Place a TImage component on your form.
Execute the following code elsewhere in your program, before the first
time you want to draw. For example in the OnCreate event of the form.

var
  Bitmap : TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.Width := 100;  (* or what else you what *)
  (* Perhaps you have also to change the size of the TImage component,
  (* I'm not exactly sure *)
  Bitmap.Height := 100;

  TheImage.Picture.Graphic := Bitmap;
end;

From now on you can draw on the TheImage.Canvas. It will automaticaly
repaint if nessessary.

if you have access to all needed data, it's better to use the OnPaint
event of the component on which canvas you draw. The OnPaint event will
be executed every time a repaint is nessessary.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Research Station for Cattle, Sheep and Horse Husbandry (PR)
Runderweg 6          8219 PK Lelystad       The Netherlands
E-mail: J.Mossel...@pr.agro.nl   Fax nr: +31 (0)320 241 584

Other Threads