2 pièce(s) jointe(s)
Visualiser un graphique et une image l'un après l'autre
Bonjour,
j'ai une image en fond d'écran de mon application.
Puis je veux effacer l'image et la remplacer par une PaintBox.
Lorsque j'ai fini, j'efface la PaintBox et je réaffiche l'image en fond d'écran.
Mais lorsque je veux afficher la PaintBox, l'image s'efface, mais la PaintBox n'apparaît pas.
Il faut que je represse sur le bouton PaintBox pour qu'elle s'affiche enfin.
Le Bitmap sert à construire l'image qui est ensuite dessinée dans la PaintBox.
Où se trouve l'erreur ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| unit UnitGraph;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons,
StdCtrls, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
PaintBox1: TPaintBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
public
{ public declarations }
Procedure Affich(Sender: TObject); // affichage des graphes
private
{ private declarations }
FGph : TBitmap;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
//******************************************************************************
//************************** Affichage des graphes *************************
//******************************************************************************
procedure TForm1.Affich(Sender: TObject);
Const
ClrFond = Clgreen;
begin
Image1.Visible:=false;
Paintbox1.Align:=AlClient;
FGph.Height:=Paintbox1.Height;
FGph.Width:=Paintbox1.Width;
FGph.Canvas.brush.Color:=ClrFond ;
FGph.Canvas.pen.Color:=ClrFond ; // si la couleur n'est pas celle du fond, un cadre apparaît de la couleur du stylo
FGph.Canvas.rectangle(0, 0, FGph.Width, FGph.Height); // -----> efface la fenêtre
FGph.Canvas.pen.Color:=ClBlack; // si la couleur n'est pas celle du fond, un cadre apparaît de la couleur du stylo
FGph.canvas.moveto(100, 100); // construction des axes des abscisses
FGph.canvas.lineto(150, 150);
Paintbox1.Canvas.Draw(0, 0, FGph); // transfère le dessin dans la Paintbox
Paintbox1.Visible:=true;
end;
//******************************************************************************
//********************* Fin de l'affichage des graphes *********************
//******************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
begin
Affich(Sender);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Paintbox1.Visible:=false;
Image1.Visible:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FGph:=TBitmap.Create;
end;
end. |
Voici le code complet du petit programme : Pièce jointe 511229
Merci et bonne journée
Raffraichissement de la PaintBox
Merci pour la réponse.
effectivement, il faut transférer le dessin du Bitmap dans l'événement 'OnPaint' de la Paintbox.
bonne journée.