Setting up background images for forms in Delphi

前端 未结 4 619
后悔当初
后悔当初 2020-12-22 01:48

How can I make my program load an image and make it the background for a form? I need the exact code for it. I\'ve looked all over the internet and the only things I\'ve fo

4条回答
  •  醉梦人生
    2020-12-22 02:25

    What I would do is use the forms OnPaint event, get the canvas (Form1.Canvas), and then use the Draw method (which takes an image) to draw the image you want. Something like the following:

    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;

    Note that this could be extremely slow.

提交回复
热议问题