To write the OnClick event handler

1. In the Object Inspector, double-click the Button1 OnClick event on the Events tab.

The Code editor displays with the cursor in the TForml.Buttonlciick event handler block.

2. Enter the following event handling code, replacing MyFile.bmp with the name of the bitmap image in your project directory:

Rect := TRect.Create(0,0,100,100); Bitmap := TBitmap.Create;

  1. LoadFromFile('MyFile.bmp'); Form1.Canvas.Brush.Bitmap := Bitmap; Form1.Canvas.FillRect(Rect); finally
  2. Canvas.Brush.Bitmap := nil; Bitmap.Free; end;

Tip: You can change the size of the rectangle to be displayed by adjusting the Rect parameter values.

3. In the var section of the code, add these variable declarations:

Bitmap : TBitmap; Rect : TRect;

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment