Solved

refresh canvas

Posted on 2001-09-03
7
2,108 Views
Last Modified: 2010-05-18
i"m using canvas on Panel  

ACanvas := TControlCanvas.Create;
TControlCanvas(ACanvas).Control := Panel1;

My project use the canvas to draw lines so the refresh action is important .

Apparently when the Panel is large (beyond the screen size , ...the scroll is used) the refresh is efficient until some specific horizontal point.
from this point the refresh is "die",

greatefull for any help

0
Comment
Question by:asi
  • 3
  • 2
  • 2
7 Comments
 
LVL 33

Expert Comment

by:Slick812
ID: 6451288
whenever a control (component) is redrawn (refreshed) this does a "Paint" procedure. If you want to keep your lines visible then you will have to redraw them in the component's (Panel) Paint procedure. I use a TPaintBox to draw on, it has an OnPaint method. If your lines are complex, then you can draw them on a memory Bitmap Canvas at the same time you draw on the Panel canvas and have the memory bitmap (with lines), drawn on the visible panel canvas during a Paint procedure.
0
 

Author Comment

by:asi
ID: 6451308
memory Bitmap Canvas  ?
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6451808
yes, , , Maybe you don't work with Bitmap graphics much? You create a Bitmap and give it the same width and height as your client area of the panel then Copy the Panel Canvas to the bitmap canvas. Then you can draw on it or copy your panel canvas to it after you draw on the Panel canvas. A TPanel already has a Canvas property, so I don't know why you did this -
ACanvas := TControlCanvas.Create;
TControlCanvas(ACanvas).Control := Panel1;
? ? ?

here is some code that I use with a TPaintBox which is better to draw on than a TPanel - - -

    private
    { Private declarations }
    BasePic:TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
begin
{create your BasePic bitmap}
BasePic := TBitmap.Create;
BasePic.Width := PaintBox1.Width;
BasePic.Height := PaintBox1.Height;
{now fill in your Paintbox with some lines or what you
need to see there}
PaintBox1.Canvas.Brush.Color := clWhite;
PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
PaintBox1.Canvas.Pen.Color := clRed;
PaintBox1.Canvas.MoveTo(10,12);
PaintBox1.Canvas.LineTo(42,31);
PaintBox1.Canvas.LineTo(133,7);
{now copy your PaintBox1 Canvas to yor BasePic Canvas}
BasePic.Canvas.CopyRect(PaintBox1.ClientRect, PaintBox1.Canvas, PaintBox1.ClientRect);
{now you have a memory bitmap - BasePic - to use to paint
your paintbox}
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
{this is the refresh painting of your paintbox
which draws the BasePic on the paintbox}
PaintBox1.Canvas.Draw(0,0,BasePic);
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
{move the pen to X, Y  where the mouse button goes down}
PaintBox1.Canvas.MoveTo(X,Y);
end;

procedure TForm1.PaintBox11MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
{draw a line to X,Y where the mouse button went up}
PaintBox1.Canvas.LineTo(X,Y);
{after you draw the line copy the paintbox canvas to the BasePic}
BasePic.Canvas.CopyRect(PaintBox1.ClientRect, PaintBox1.Canvas, PaintBox1.ClientRect);
{now the Base Pic looks like the paintbox with NEW line}
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
BasePic.Free;
end;

 - - - - - - - - - - - - - - - - - -

I hope this gives you the idea, , , ,
let me know
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:asi
ID: 6453096

My application need to draw lines between controls.

The problem that TPaintBox is not descendent from

TWinControl (... and can not bs parent) so to connect

controls with lines become ... impossible.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 100 total points
ID: 6454604
you did not say anything about other factors, just drawing lines. . . . Instead of trying to tell you how to get a TPanel Paint event, here is a component called PaintPanel, which has the Canvas property and OnPaint event added to a TPanel. . . install this componet and you can use some of the paintbox code, using PaintPanel1 instead Of PaintBox1
 - - - - - - - - - - - - - -

unit PaintPanel;

interface
uses
  Windows, Messages, {Forms,} Classes, extctrls, Graphics{, Controls};

type
TPaintPanel = class(TPanel)
  private
  { Private declarations }
    FOnPaint: TNotifyEvent;

  protected
  { Protected declarations }
    procedure Paint; override;

  public
  { Public declarations }
    property Canvas;

  published
  { Published declarations }
    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;

end;

procedure Register;

implementation

procedure Register;
  begin
    RegisterComponents('Samples', [TPaintPanel]);
  end;

procedure TPaintPanel.Paint;
begin
inherited;
if Assigned(FOnPaint) then FOnPaint(Self);
end;

end.


 - - - - - - - - - - - - - - - - - -
hope you can use this
let me know
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6844662
Question(s) below appears to have been abandoned. ADMINISTRATION HAS BEEN ADVISED AND WILL BE CONTACTING YOU SHORTLY.  There are a total of 57 open questions for you, any not shown here have ZERO comments added, so you can delete them directly.

Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11624838.html
http://www.experts-exchange.com/questions/Q.11837819.html
http://www.experts-exchange.com/questions/Q.12000718.html
http://www.experts-exchange.com/questions/Q.20015588.html
http://www.experts-exchange.com/questions/Q.20033766.html
http://www.experts-exchange.com/questions/Q.20060547.html
http://www.experts-exchange.com/questions/Q.20086506.html
http://www.experts-exchange.com/questions/Q.20087146.html
http://www.experts-exchange.com/questions/Q.20096878.html
http://www.experts-exchange.com/questions/Q.20099988.html
http://www.experts-exchange.com/questions/Q.20103524.html
http://www.experts-exchange.com/questions/Q.20105868.html
http://www.experts-exchange.com/questions/Q.20124168.html
http://www.experts-exchange.com/questions/Q.20126164.html
http://www.experts-exchange.com/questions/Q.20126258.html
http://www.experts-exchange.com/questions/Q.20127406.html
http://www.experts-exchange.com/questions/Q.11610958.html
http://www.experts-exchange.com/questions/Q.20136024.html
http://www.experts-exchange.com/questions/Q.20137249.html
http://www.experts-exchange.com/questions/Q.20147343.html
http://www.experts-exchange.com/questions/Q.20162739.html
http://www.experts-exchange.com/questions/Q.20163581.html
http://www.experts-exchange.com/questions/Q.20165158.html
http://www.experts-exchange.com/questions/Q.20167166.html
http://www.experts-exchange.com/questions/Q.20177854.html
http://www.experts-exchange.com/questions/Q.20185774.html
http://www.experts-exchange.com/questions/Q.20185782.html
http://www.experts-exchange.com/questions/Q.20211426.html
http://www.experts-exchange.com/questions/Q.20211827.html
http://www.experts-exchange.com/questions/Q.20229407.html
http://www.experts-exchange.com/questions/Q.20231198.html
http://www.experts-exchange.com/questions/Q.20238567.html
http://www.experts-exchange.com/questions/Q.20238568.html
http://www.experts-exchange.com/questions/Q.20238571.html
http://www.experts-exchange.com/questions/Q.20240061.html
http://www.experts-exchange.com/questions/Q.20241871.html
http://www.experts-exchange.com/questions/Q.20242268.html
http://www.experts-exchange.com/questions/Q.20244256.html
http://www.experts-exchange.com/questions/Q.20246106.html
http://www.experts-exchange.com/questions/Q.20250445.html
http://www.experts-exchange.com/questions/Q.20251868.html
http://www.experts-exchange.com/questions/Q.20254886.html
http://www.experts-exchange.com/questions/Q.20254704.html
http://www.experts-exchange.com/questions/Q.20255422.html
http://www.experts-exchange.com/questions/Q.20261740.html
http://www.experts-exchange.com/questions/Q.20262552.html
http://www.experts-exchange.com/questions/Q.20262985.html
http://www.experts-exchange.com/questions/Q.20265275.html
http://www.experts-exchange.com/questions/Q.20270259.html
http://www.experts-exchange.com/questions/Q.20270694.html
http://www.experts-exchange.com/questions/Q.20270687.html
http://www.experts-exchange.com/questions/Q.20271885.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20171579.html
http://www.experts-exchange.com/questions/Q.20178687.html
http://www.experts-exchange.com/questions/Q.20265222.html
http://www.experts-exchange.com/questions/Q.20265219.html
http://www.experts-exchange.com/questions/Q.20269116.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6851622
Thanks for returning and finalizing your question.  Anytime you choose to grade less than an A, please comment as to why.  This helps all involved, including others who may visit this question at a later time for help.  Some experts look at grading history before deciding to help someone, so that also may have an impact to you and how quickly your future questions are answered.

The points to you are always the same, but the points granted the expert depend upon the grade.  Using 100 points as an example.  100 at A = 400 ... 100 at B = 300 .... 100 at C = 200, so it also has a point impact to the experts.  

If the grade chosen was in error, let me know, and I can correct this.

EE Moderator
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now