Autor Beitrag
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Fr 01.04.05 14:28 
Kann ich einem Formular ein Hintergrundbild zuweisen???
Oder hat jemand ne gute Idee wo aufs gleich raus kommt?


Moderiert von user profile iconGausi: Topic aus CLX / Delphi Language (Object-Pascal) verschoben am Fr 01.04.2005 um 15:38
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 18:00 
Mach dir ein TImage auf's Formular. Irgendwohin. Dann schreibst du das da in Form1OnCreate:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Image1.SendToBack;
Image1.Align := clClient;
Image1.Stretch := True;  //u.U. anpassen
Image1.Picture.LoadFromFile('bild.bmp');


Ich versuch grad ne Funktion dafür zu schreiben, dass man auch kein TImage mehr während der Erstellzeit draufsetzen muss. :nixweiss:
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 01.04.05 18:10 
user profile iconWeBsPaCe hat folgendes geschrieben:
Mach dir ein TImage auf's Formular. Irgendwohin. Dann schreibst du das da in Form1OnCreate:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Image1.SendToBack;
Image1.Align := clClient;
Image1.Stretch := True;  //u.U. anpassen
Image1.Picture.LoadFromFile('bild.bmp');


Ich versuch grad ne Funktion dafür zu schreiben, dass man auch kein TImage mehr während der Erstellzeit draufsetzen muss. :nixweiss:


Ich will ja nicht klugscheissen, aber Bringtofront bzw. SendtoBack funktioniert nur bei Klassen die von TWinControl abgeleitet wurden.

Ein TImage ist abgeleitet von TGraphicControl, weswegen SendToBack überflüssig ist.

zu deiner Funktion, wie wärs hiermit:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Background(Img : String);
var Back : TImage;
begin
 Back := Timage.Create;
  with back do
   begin
    align := alclient;
    picture.loadfromfile(img);
    stretch := true;
   end;
end;


Zuletzt bearbeitet von Karlson am Fr 01.04.05 18:39, insgesamt 1-mal bearbeitet
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 18:16 
Achso... :oops:

Ist das dann automatisch hinten??? :gruebel: Und was ist, wenn zwei TImages aufeinander liegen??
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 01.04.05 18:41 
user profile iconWeBsPaCe hat folgendes geschrieben:
Achso... :oops:

Ist das dann automatisch hinten??? :gruebel: Und was ist, wenn zwei TImages aufeinander liegen??


Bei zwei Images funktioniert alles, sind schließlich bei TGraphicControl. Erst wenn ein TWinControl dazukommt wirds problematisch.

Was hast du gemeint mit Funktion zum automatischem Backgroundsetzen?
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 19:18 
Hmm?? Ich glaub wir reden grad anneinander vorbei... ;)

(1) Ich bin dabei (5 min ;) ) zwei Funktionen zu schreiben, mit denen man einen Hintergrund festlegen kann und auch wieder löschen. ;)

(2) Ich hab das SendToBack dringehabt, weil ich dachte, wenn ich das TImage erst zur Laufzeit erstell', dann kann's ja sein, dass es vorne dran hängt (also vor Buttons oder andren Images). Deshalb wollte ich wissen warum das nicht geht. ;)

Danke schonmal. ;)
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 01.04.05 19:37 
Jo, also ich hab mich jetzt eigentlich darauf bezogen:

Zitat:

Ich versuch grad ne Funktion dafür zu schreiben, dass man auch kein TImage mehr während der Erstellzeit draufsetzen muss.


Wenn ich dein Problem richtig verstanden habe, dann müsste das so gehen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Background(Img : String);
var Back : TImage;
begin
 Back := Timage.Create;
  with back do
   begin
    align := alclient;
    picture.loadfromfile(img);
    stretch := true;
   end;
end;


Du sagtest ja, du willst kein Image zur Entwurfszeit einfügen müssen.

Ich dachte du willst wissen wie das geht, wegen dem Smiley.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 10:51 
So. Hab jetzt die beiden procedures fertig. ;)

Zum Setzen eines Hintergrunds.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure SetBackground(aForm: TForm; aPath: String; aStretch: Boolean);
var
BkgrndImage: TImage;
begin
if TImage(aForm.FindComponent('BkgrndImage')) <> nil then
with TImage(aForm.FindComponent('BkgrndImage')) do begin
Picture.LoadFromFile(aPath);
Stretch := aStretch;
end else begin
BkgrndImage := TImage.Create(aForm);
BkgrndImage.Align := alClient;
BkgrndImage.Parent := aForm;
BkgrndImage.Picture.LoadFromFile(aPath);
BkgrndImage.Stretch := aStretch;
BkgrndImage.Name := 'BkgrndImage';
end;
end;

Zum Entfernen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure ClearBackground(aForm: TForm);
begin
with TImage(aForm.FindComponent('BkgrndImage')) do Free;
end;

;)
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 12:49 
Nach extremer Mithilfe von user profile iconSprint sind jetzt diese folgenden vier procedures entstanden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure ClearFormBackground(aForm: TForm);
begin
if TImage(aForm.FindComponent(aForm.Name + '_BkgrndImage')) <> nil then
with TImage(aForm.FindComponent(aForm.Name + '_BkgrndImage')) do Free;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure SetFormBackground(aForm: TForm; aPath: String; aStretch: Boolean);
var
BkgrndImage: TImage;
begin
if TImage(aForm.FindComponent(aForm.Name + '_BkgrndImage')) <> nil then
with TImage(aForm.FindComponent(aForm.Name + '_BkgrndImage')) do begin
Picture.LoadFromFile(aPath);
Stretch := aStretch;
end else begin
BkgrndImage := TImage.Create(aForm);
BkgrndImage.Align := alClient;
BkgrndImage.Parent := aForm;
BkgrndImage.Picture.LoadFromFile(aPath);
BkgrndImage.Stretch := aStretch;
BkgrndImage.Name := aForm.Name + '_BkgrndImage';
end;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure ClearAllFormsBackground;
var
i: Integer;
begin
for i := 0 to Application.ComponentCount - 1 do
if Application.Components[i] is TForm then
if TImage(Application.Components[i].FindComponent(Application.Components[i].Name + '_BkgrndImage')) <> nil then
with TImage(Application.Components[i].FindComponent(Application.Components[i].Name + '_BkgrndImage')) do Free;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure SetAllFormsBackground(aPath: String; aStretch: Boolean);
var
i: Integer;
BkgrndImage: TImage;
begin
for i := 0 to Application.ComponentCount - 1 do
if Application.Components[i] is TForm then begin
if TImage(Application.Components[i].FindComponent(Application.Components[i].Name + '_BkgrndImage')) <> nil then
with TImage(Application.Components[i].FindComponent(Application.Components[i].Name + '_BkgrndImage')) do begin
Picture.LoadFromFile(aPath);
Stretch := aStretch;
end else begin
BkgrndImage := TImage.Create(Application.Components[i]);
BkgrndImage.Align := alClient;
BkgrndImage.Parent := TForm(Application.Components[i]);
BkgrndImage.Picture.LoadFromFile(aPath);
BkgrndImage.Stretch := aStretch;
BkgrndImage.Name := Application.Components[i].Name + '_BkgrndImage';
end;
end;
end;


Danke nochmal, Sprint!! ;)
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Mo 04.04.05 07:43 
OK, viel Dank.