Reputation: 27
I've been trying to display a rectangle by creating a canvas on a bitmap. It looks like this:
TRoom = class
private
width, length, X1,X2,Y1,Y2, index: integer;
public
plane: TBitmap;
procedure draw;
procedure setparam;
function getparam: integer;
end;
procedure TRoom.draw;
begin
plane:= TBitmap.create;
plane.canvas.Pen.Color:= 1791767;
plane.Canvas.pen.Width:= 3;
plane.canvas.Rectangle(10,10,20,20);
end;
As stated in the title, neither the canvas, nor the rectangle appear. I have never worked with the canvas in Delphi before so I expect it to be something rather trivial.
Upvotes: 0
Views: 1089
Reputation: 613511
A TBitmap
is a non visual class that represents a raster image, a 2D array of pixels. On its own it is never visible. You would need to paint it on the screen in order to see it.
What you should do is create a visual control to which you can paint. For instance a TPaintBox
. Put one of those on your form and add a handler for its OnPaint
event.
procedure TForm1.PaintBox1Paint(Sender: TCanvas);
begin
PaintBox1.Canvas.Pen.Color :=. 1791767;
PaintBox1.Canvas.Pen.Width := 3;
PaintBox1.Canvas.Rectangle(10, 10, 20, 20);
end;
Upvotes: 2