Recent

Author Topic: Unvisual TPaintBox creation  (Read 4346 times)

bakacirno

  • Newbie
  • Posts: 2
Unvisual TPaintBox creation
« on: May 18, 2012, 05:13:45 am »
Hello, im trying to create working TPaintBox without lazarus help, i.e. in plain text, but it doesnt work for me no matter what i try
Im trying it like that:
Code: [Select]
unit main;
{$mode objfpc}{$H+}
interface
uses
 Classes, SysUtils, Forms, Controls, Dialogs, ExtCtrls, Menus, Graphics;
type
 TForm1 = class(TForm)
  PaintBox1: TPaintBox;
  procedure FormCreate(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
 PaintBox1 := TPaintBox.Create(Self);
 PaintBox1.Parent := Form1;
 PaintBox1.Visible := true;
 PaintBox1.Align := alClient;
 PaintBox1.Canvas.Pen.color := clBlack;
 PaintBox1.Canvas.FillRect(20,20,40,40);
end;
end.
It gives me an empty form without black rectangle which is supposed to be here, what i am doing wrong? I googled hard, but no luck.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8319
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Unvisual TPaintBox creation
« Reply #1 on: May 18, 2012, 08:20:49 am »
Create an OnPaint event for PaintBox1, assign it to PaintBox1.OnPaint, and move the FillRect there.

bakacirno

  • Newbie
  • Posts: 2
Re: Unvisual TPaintBox creation
« Reply #2 on: May 18, 2012, 08:52:55 am »
Many thanks for you reply, now it works. I was looking for some sort of OnCreate method for PaintBox, but found none. I was thinking OnPaint is for events related for actually painting on canvas. Also sorry, i didnt meant to create topic in Suggensions forum section, it was an accident.

 

TinyPortal © 2005-2018