![]() |
bmp in Panel zeichnen
Hallo,
kann man ein bmp in einen Panel zeichnen ohne Paintbox oder TImage? |
Re: bmp in Panel zeichnen
Leite Dir eine Klasse von TPanel ab, mache dort die Canvas-Eigenschaft öffentlich und zeichne dann darauf.
|
Re: bmp in Panel zeichnen
Oder ohne Ableiten mittels GetWindowDC, ein kleines Beispiel:
Delphi-Quellcode:
Gruß
procedure TForm1.Button1Click(Sender: TObject);
var X: TBitmap; H: HDC; begin X := TBitmap.Create; try X.Width := 20; X.Height := 20; X.Canvas.Ellipse(0, 0, 20, 20); H := GetWindowDC(Panel1.Handle); BitBlt(H, 0, 0, 20, 20, X.Canvas.Handle, 0, 0, SRCCOPY); finally X.Free; end; end; |
Re: bmp in Panel zeichnen
Hast du darüber zufällig ein Tutorial?
Habe soetwas noch nie gemacht. |
Re: bmp in Panel zeichnen
Da vermisse ich aber ein ReleaseDC ;)
[edit] Zitat:
|
Re: bmp in Panel zeichnen
Zitat:
Also, dahinter noch ein
Delphi-Quellcode:
Ich hoffe das stimmt jetzt so..
ReleaseDC(Panel1.Handle, H);
|
Re: bmp in Panel zeichnen
@Fussball-Robby ...und dach dem verschieben oder wenn ein fenster drüber war ist alles pfutsch. ;)
|
Re: bmp in Panel zeichnen
Du musst natürlich im Ereignis Onpaint des Formulars oder Panels immer wieder alles neu reinmalen.
Das übernimmt ansonsten Delphi für Dich, da aber Delphi nix davon weiß, weil Du ja keine Paintbox genommen hast, dann musst Du Dich selbst um das neuzeichnen kümmern .. |
Re: bmp in Panel zeichnen
Also in etwa so:
Delphi-Quellcode:
Das ist natürlich nur ein Beispiel, man kann die Bitmap auch zum Programmstart einmalig laden und im Speicher halten etc.
...
interface uses ..., ExtCtrls; type TPanel = class(ExtCtrls.TPanel) protected procedure Paint;override; //erspart dann das Öffentlichmachen von Canvas end; TForm1 = class(TForm) Panel1: TPanel; ... end; ... implementation procedure TPanel.Paint; var bmp: TBitmap; begin inherited; bmp := TBitmap.Create; try bmp.LoadFromFile('C:\Program Files\Common Files\CodeGear Shared\Images\BackGrnd\Calendar.bmp'); Canvas.Draw(0,0,bmp); finally bmp.Free; end; end; ... |
Re: bmp in Panel zeichnen
Oder So:
Delphi-Quellcode:
- eine neues Project erstellen
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TPanel = class(ExtCtrls.TPanel) // Wichtig, als erstes for TForm1 private { Private-Deklarationen } FOnPaint: TNotifyEvent; protected { Protected-Deklarationen } procedure Paint; override; public { Public-Deklarationen } property Canvas; published { Published-Deklarationen } property OnPaint: TNotifyEvent read FOnPaint write FOnPaint; end; type TForm1 = class(TForm) Panel1: TPanel; procedure FormCreate(Sender: TObject); private { Private-Deklarationen } procedure OnPanel1Paint(Sender: TOBject); public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TPanel.Paint; begin inherited; if assigned(fOnPaint) then fOnPaint(Self); end; procedure TForm1.FormCreate(Sender: TObject); begin Panel1.OnPaint := OnPanel1Paint; end; procedure TForm1.OnPanel1Paint(Sender: TOBject); var r: Trect; begin r := Panel1.ClientRect; InflateRect(r, -2, -2); With Panel1 do begin Canvas.Brush.Color := clWindow; Canvas.RoundRect(r.Left, r.Top, r.Right, r.Bottom, 20, 20); Canvas.Brush.Color := Panel1.Color; Canvas.Draw(5, 5, Application.Icon); end; end; end. - Ein Panel auf eine Form klatschen - zwei mal auf die Form klicken und sich im FormCreate wiederfinden - Copy & Paste mit diesem Quelltext den alten Quelltext ersetzen - fertisch. //Edit: @Detlef, das gibt ne Beule ! ;)
Code:
procedure [color=#ff001f]TPanel.Paint;[/color] [color=#ff001f] <--<<<[/color]
var bmp: TBitmap; begin ... bmp.[color=#ff001f]LoadFromFile[/color]('C:\Program Files\Common Files\CodeGear Shared\Images\BackGrnd\Calendar.bmp'); [color=#ff001f]<--<<<[/color] ... end; |
Re: bmp in Panel zeichnen
Zitat:
Man muss das Panel mit einer Komponente überdecken, die eine Canvas bereitstellt. Mit deren Methoden Draw bzw. StretchDraw kann man die bmp anzeigen. |
Re: bmp in Panel zeichnen
Zitat:
|
Re: bmp in Panel zeichnen
@Matti: wie ich oben bereits schrieb, ist das ja auch nur ein Beispiel, es ging ja nicht darum, wo die Bitmap jetzt herkommt ;)
@Ernst: und was ist mit den Codebeispielen weiter oben? |
Re: bmp in Panel zeichnen
warum unbedingt ein TPanel? leite einfach von TCustomControl ab, da hast ein Control mit Canvas...und sparst die Implementation des Canvas/OnPaint
Gruß Frank |
Re: bmp in Panel zeichnen
Einen echten Vorteil kann ich darin aber nicht erkennen. Wenn man ein Panel nimmt, kann man das wie gewohnt zur Designtime einstellen und sehen (nur eben ohne die Grafik).
|
Re: bmp in Panel zeichnen
Noch eine möglichkeit währe, das TJVPanel (aus den Jedis) zu verwenden! Dieses besitzt auch die möglichkeit ohne ableitung auf den Canvas zuzugreifen. So kannst du das Bild wie oben beschrieben auf das Panel zeichnen!
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:18 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz