Solved

Background Picture on form.

Posted on 1998-07-26
2
195 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

14 Experts available now in Live!

Get 1:1 Help Now