Setting background images for forms in Delphi

How can I make my program load an image and make it the background for the form? I need the exact code. I looked all over the internet and the only thing I found was various settings and fixes to make the backgrounds work as intended in special circumstances. I also tried some Delphi books that I have, and I can't find it anywhere.

+1
source share
4 answers
  • Put a TImageon your form. Make sure that these are behind all the other controls on the form. You can right-click it and select the "send back" option.

  • Download the graphics.

    var
      img: TBitmap;
    begin
      img := TBitmap.Create;
      try
        img.LoadFromFile('S:\background.bmp');
    
  • Assign it to an image control.

        Image1.Picture := img;
    
  • Cleaning up.

      finally
        img.Free;
      end;
    end;
    

, . .

Image1.Picture.LoadFromFile('B:\background.bmp');

: Delphi

+4

, OnPaint, (Form1.Canvas), Draw ( ), . - :

procedure TForm1.FormPaint(Sender: TObject);
var
mypic: TBitMap;
begin
mypic := TBitMap.Create;
try
mypic.LoadFromFile('cant.bmp');
Form1.Canvas.Draw(0, 0, mypic);
finally
FreeAndNil(mypic);
end;
end;

, .

0

, .

  var
    vDest, vRect:  TRect;
  begin
    vRect := Rect(0, 0, FBackgroundImage.Width, FBackgroundImage.Height);
    vDest := Rect(0,0,Self.Width, Self.Height);
    Canvas.StretchDraw(vDest, FBackgroundImage);


  if FileExists(this) then
    FBackgroundImage.LoadFromFile(this);
0

@Brendan

thanks
//from Brendan code;

var
vDest, vRect:  TRect;
FBackgroundImage: TGraphic;
begin
FBackgroundImage := image1.Picture.Graphic; //LOAD from invisible image
vRect := Rect(0, 0, FBackgroundImage.Width, FBackgroundImage.Height);
vDest := Rect(0,0,Self.Width, Self.Height);
Canvas.StretchDraw(vDest, FBackgroundImage);
end;
0

All Articles