Autor Beitrag
Bestzeller
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 48



BeitragVerfasst: Mo 15.12.08 19:52 
Hallo Zusammen
Ich möchte gerne wissen, wie ich das Bild in der Paintbox verschwinden lasse,
denn ich will ein anderes Bild hineinkopeieren, aber wenn ich dies tue erscheint es nur kurz
und das alte bild ist wieder da. Brauch ich vielleicht eine ganz neue Paintbox, weil das zweite Bild kleiner ist?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 15.12.08 20:30 
Reden wir hier von TPaintbox oder von TImage? Bei Ersterem würde ich einfach mit FillRect das Ganze übermalen, bei Zweiterem nil als Picture zuweisen.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mo 15.12.08 20:50 
Hi :)

Bei einer paintbox sollte ein einfaches Paintbox1.Repaint; genügen. Beachte allerdings, wie eine Paintbox funktioniert: Sie sollte stets ausschließlich in ihrem OnPaint-Ereignis bemalt werden.

Um also ein neues Bild in eine Paintbox zu laden, deklarierst du eine Feldvariable vom Typ TBitmap. In diese lädst du dann das neue Bild. Im OnPaint sollte nun immer der in der Feldvariable befindlcihe Bild per StretchDraw auf die Paintbox gemalt werden:

ausblenden Delphi-Quelltext
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:
type
  TForm1 = class (TForm)
  {..}
    Paintbox1: TPaintbox;
    procedure FormCreate(Sender: TObject);
    procedure Paintbox1Repaint(Sender: TObject);
  private
    FBmp: TBitmap;
  public
    { public declarations }
  end;

{..}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FBmp := TBitmap.Create;
  FBmp.LoadFromFile({..});
end;

procedure TForm1.Paintbox1Repaint(Sender: TObject);
begin
  Paintbox1.Canvas.StretchDraw(FBmp, Paintbox1.ClientRect);
end;

//zum Laden eines neuen bildes jetzt:
FBmp.LoadFromFile();  //neue Bilddatei; alternativ auch per canvas bemalen, etc.
Paitnbox1.Repaint;  //änderungen wirksam machen: würde sonst erst beim vergrößern des Formulars/etc. aktualisiert


mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)


Zuletzt bearbeitet von Hidden am Sa 08.08.09 11:58, insgesamt 1-mal bearbeitet
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Mo 15.12.08 21:04 
Du kannst den Inhalt mit PaintBox1.Refresh löschen.
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Di 16.12.08 00:58 
Wichtig wäre wohl hier noch zu fragen wie die Paintbox verwendet wird.

Zitat:
Sie sollte stets ausschließlich in ihrem OnPaint-Ereignis bemalt werden.


Wenn er dies macht, reicht es nicht einfach mal Paintbox1.Repaint(); aufzurufen.

;)

_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Mi 17.12.08 18:20 
PaintBox1.Refresh funktioniert doch in jedem Fall.
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Mi 17.12.08 21:18 
Repaint ruft OnPaint auf, wenn darin gemalt wird ist's ja wieder Sichtbar gelle.

_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Mi 17.12.08 21:55 
Ich rede von "Refresh" und nicht "Repaint".
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 17.12.08 22:31 
Aber beim Refresh isses wieder da, sobald es halt neugezeichnet wird :nixweiss: :nixweiss: :nixweiss:
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Mi 17.12.08 22:54 
Refresh, löscht jedes Bild auf dem Bildschirm und zeichnet alles neu.
Repaint, zeichnet jedes Bild auf dem Bildschirm neu, ohne Vorhandenes zu löschen.


Btr. Problemchen:

PaintBox ist eigentlich nur ein Platzhalter mit einem Canvas.
Verwende ein Bitmap welches in der Paintbox dargestellt wird.

Willst du nun etwas löschen, mach es auf dem Bitmap zB. mit FillRect() etc.

in sofern (siehe Anhang)
Einloggen, um Attachments anzusehen!
_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P
Bestzeller Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 48



BeitragVerfasst: Fr 19.12.08 19:54 
Hm irgentwie will das nicht ich habs mal so hingeschrieben:
(timer1 und 2 bewegen ein Objekt in der Paintbox;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  timer1.enabled:=false; 
  timer2.enabled:=false;
  paintbox1.Width:=450;
  paintbox1.Height:=517;
  bmp2:=tbitmap.create;
  bmp2.LoadFromFile(file5);
  paintbox1.canvas.FillRect(rect(0,0,517,450)) ;
  bitblt(form1.paintbox1.Canvas.handle,0,0,517,450,bmp2.canvas.handle,0,0,srccopy);


Das Bild (hier:file5) erscheint zwar kurz, aber dann taucht wieder das Bild auf was davor in die Paintbox kopiert wurde.
Liegt es daran das ich nicht das OnPaint-Ereignis benutze?
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 19.12.08 20:20 
Hi :)

Am besten ist es wohl du stellst deinen bisherigen Quelltext einfach mal vollständig hier rein :)

Zitat:
Liegt es daran das ich nicht das OnPaint-Ereignis benutze?
Kann ich so nicht sagen. Ich würde dir aber raten, die PB so zu benutzen, wie sie gedacht ist. Lässt sich sicher schnell udn einfach umschreiben.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)