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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Canvas.Draw should stay on Form1.Refresh.. It doesn't

Say I have a form, and say that form's got a canvas (wow!).

If i'd have a bitmap like this:

var bmp : TBitmap

And I'd load a bitmap into it, much like this:

bmp := TBitmap.Create;
bmp.loadfromfile('bitma.bmp');

Then if I'd do this with my canvas:

form1.canvas.draw(10,10,bmp);

it would draw the bitmap with the left top corner on 10,10.
So far, so good..

However, if I now do a form1.refresh, the canvas gets reset
to the default form1.colour. This also happens if I drag
a window over pieces of the canvas that have been drawn over.

I would actually like the canvas to keep what it's got, even
on a refresh. I've tried this with a TPaintBox, but it did
quite the same.

binkzz
0
binkzz
Asked:
binkzz
  • 4
  • 2
  • 2
1 Solution
 
erajojCommented:
Put it in "OnPaint".

/// John
0
 
binkzzAuthor Commented:
small example?
0
 
viktornetCommented:
Here is an example....

var
  BMP : TBitmap;

//OnCreate()
procedure TForm1.Form1Create(Sender : TObject);
begin
  BMP := TBitmap.Create;
  BMP.LoadFromFile('C:\windows\desktop\test.bmp');
end;
//OnDestroy()
procedure TForm1.Form1Destroy(Sender : TObject);
begin
  BMP.Free;
end;
//OnPaint()
procedure TForm1.Form1Paint(Sender : TObject);
begin
  Canvas.Draw(10,10, BMP);
end;

somewhere in your program just call Refresh...For example in the Form's OnResize()
//OnResize()
procedure TForm1.Form1Resize(Sender : TObject);
begin
  Refresh;
begin

Cheers,
Viktor
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
viktornetCommented:
oppps..... Sorry John.... PLease reject my answer and let John answer if the solution works...

Cheers,
Viktor
0
 
binkzzAuthor Commented:
John gave me the answer, you gave me the example requested. In
my opinion you both deserve the points for this, but as you did
most of the hard work, I'm affraid the points will have to go to
you.

Sorry john, life's a bitch, and then you marry one.

Binkzz
0
 
viktornetCommented:
:-|
0
 
erajojCommented:
No tengo ningĂșn problema con ese, muchacho.

/// John
0
 
viktornetCommented:
:-| . o O
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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