Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 1998-11-02
8
324 Views
Last Modified: 2012-05-04
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
Comment
Question by:binkzz
  • 4
  • 2
  • 2
8 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1345477
Put it in "OnPaint".

/// John
0
 
LVL 4

Author Comment

by:binkzz
ID: 1345478
small example?
0
 
LVL 10

Accepted Solution

by:
viktornet earned 30 total points
ID: 1345479
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 10

Expert Comment

by:viktornet
ID: 1345480
oppps..... Sorry John.... PLease reject my answer and let John answer if the solution works...

Cheers,
Viktor
0
 
LVL 4

Author Comment

by:binkzz
ID: 1345481
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1345482
:-|
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1345483
No tengo ningún problema con ese, muchacho.

/// John
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345484
:-| . o O
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question