?
Solved

URGENT: Why the content of painbox get losted ?

Posted on 2006-04-11
6
Medium Priority
?
231 Views
Last Modified: 2010-04-05
Hi,
I draw something on paintbox but if i go to another form and come back to that form again drawed paint was get losted?
Why? How can i avoid from this problem?

Regards
0
Comment
Question by:shirin
  • 4
  • 2
6 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16428921
The paintbox is not a static canvas, thus you need to perform your actions in the Paint procedure of the TPaintBox contol. Btw, if you are painting something static, you might try drawing on a bitmap, and then assigning the bitmap to a TImage control instead.

Regards,
Russell

0
 

Author Comment

by:shirin
ID: 16429417
I dont want to static this Figure.
I only Need My program Change this figure.
with  overlapping another form with  paintbox form
previous Painted figure was get losted.

0
 

Author Comment

by:shirin
ID: 16430749
OK,
with Your Guidance I found:TImage is Better For my purpose.

But i can not clear previous paint when i click a button.

I added Extra points for my last  Q.



0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 26

Accepted Solution

by:
Russell Libby earned 600 total points
ID: 16432295
You can also use the offscreen bitmap to perform updates on, then have the paintbox draw the bitmap on its canvas. Example provided below (just add you painting code to the UpdateBitmap procedure):

Regards,
Russell

----

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1            =  class(TForm)
     PaintBox1:     TPaintBox;
     Button1:       TButton;
     procedure      PaintBox1Paint(Sender: TObject);
     procedure      FormCreate(Sender: TObject);
     procedure      FormDestroy(Sender: TObject);
     procedure      Button1Click(Sender: TObject);
  private
     // Private declarations
     FBitmap:       TBitmap;
  protected
     // Protected declarations
     procedure      UpdateBitmap;
  public
     // Public declarations
  end;

var
  Form1:            TForm1;

implementation
{$R *.DFM}

procedure TForm1.UpdateBitmap;
begin

  // Update the bitmap with something
  with FBitmap.Canvas do
  begin
     FillRect(Rect(0, 0, FBitmap.Width, FBitmap.Height));
     TextOut(10, 10, 'Hello world');
  end;

  // Force paintbox to repaint
  PaintBox1.Repaint;

end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin

  // Draw the static bitmap on the paintbox control canvas
  PaintBox1.Canvas.Draw(0, 0, FBitmap);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Create bitmap
  FBitmap:=TBitmap.Create;

  // Set bounds
  FBitmap.Width:=PaintBox1.Width;
  FBitmap.Height:=PaintBox1.Height;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

  // Free the bitmap
  FBitmap.Free;
 
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  // Example of updating the bitmap
  UpdateBitmap;

end;

end.

----------

object Form1: TForm1
  Left = 232
  Top = 114
  Width = 475
  Height = 343
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object PaintBox1: TPaintBox
    Left = 104
    Top = 16
    Width = 257
    Height = 233
    OnPaint = PaintBox1Paint
  end
  object Button1: TButton
    Left = 16
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
end


0
 

Author Comment

by:shirin
ID: 16433491
Hi, How can I clear a Previous pain and paint a new one dynamically.
0
 

Author Comment

by:shirin
ID: 16433661
Ok,
I can it with
image1.picture.bitmap:=nil;
and draw another figure.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

839 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