Solved

Background Picture on form.

Posted on 1998-07-26
2
197 Views
Last Modified: 2010-04-04
How to use a bitmap as a background picture on a form in Delphi 2
0
Comment
Question by:koger
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1358705
Hi koger,

How do I paint the background of my form with a bitmap as tiles?
(from TI)

A:

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Bitmap: TBitmap;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('C:\WINDOWS\cars.BMP');
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  X, Y, W, H: LongInt;
begin
  with Bitmap do begin
    W := Width;
    H := Height;
  end;
  Y := 0;
  while Y < Height do begin
    X := 0;
    while X < Width do begin
      Canvas.Draw(X, Y, Bitmap);
      Inc(X, W);
    end;
    Inc(Y, H);
  end;
end;

end.

offcourse, it's easy to change this without tiled bitmap.

Zif.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358706
Hi koger,

To fully answer your question fully :

 add in the public section of your form :
  bmpBackground : TBitmap;

 add in the formcreate event following code :
  bmpBackground := TBitmap.Create;
  bmpBackground.LoadFromFile( 'c:\windows\setup.bmp' );

 add code in the onpaint event :
  Canvas.Draw( 0, 0, bmpBackground );

 offcourse we've to free the memmory of our bitmap, so add following code in the formdestroy event :
  bmpBackground.Free;

Zif


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 266
error 1.1 400 Bad request idhttp delphi 18 52
Create a path if not exists 7 67
Firemonkey webbrowser scrollbars ? 1 29
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now