绘图需要有纸、画笔、画刷; Delphi 有 Canvas、Pen、Brush.
Canvas 就是画布, 譬如窗体的 Canvas 属性, 就是窗体的画布;
Pen 是画笔, 可以设置笔色、笔宽等等;
Brush 是画刷, 可以设置颜色等等.
//举例: {绘制直线} procedure TForm1.Button1Click(Sender: TObject); begin Canvas.Pen.Color := clRed; {设置画笔颜色} Canvas.Pen.Width := 2; {设置画笔宽度} Canvas.MoveTo(10,10); {直线起点} Canvas.LineTo(100,100); {直线终点} {这里的 Canvas 是简写, 也可以写做: Self.Canvas 或 Form1.Canvas } end; {矩形填充} procedure TForm1.Button2Click(Sender: TObject); begin Canvas.Brush.Color := clYellow; {设置画刷颜色, 也就是填充色} Canvas.FillRect(ClientRect); {填充窗体客户区} end;
//效果图: