简体   繁体   English

(Delphi 7)在画布(以及画布本身)上绘制的对象没有出现

[英](Delphi 7) Object drawn on canvas (and the canvas itself) does not appear

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. 我以前从未在Delphi中使用过画布,因此我希望它会变得相当琐碎。

A TBitmap is a non visual class that represents a raster image, a 2D array of pixels. TBitmap是一种非可视类,它表示栅格图像,二维像素数组。 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 . 例如一个TPaintBox Put one of those on your form and add a handler for its OnPaint event. 将其中之一放在表单上,​​并为其OnPaint事件添加一个处理程序。

procedure TForm1.PaintBox1Paint(Sender: TCanvas);
begin
  PaintBox1.Canvas.Pen.Color :=. 1791767;
  PaintBox1.Canvas.Pen.Width := 3;
  PaintBox1.Canvas.Rectangle(10, 10, 20, 20);
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM