Discuz! BBS

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 576|回复: 0

Delphi 建立一个到处可用的绘图组件

[复制链接]

254

主题

363

帖子

2431

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2431
发表于 2024-12-13 04:20:28 | 显示全部楼层 |阅读模式
建立一个自定义控件,该控件在paint事件中绘制一个图形:
  1. unit CustomShapeControl;

  2. interface

  3. uses
  4.   System.Classes, Vcl.Controls, Vcl.Graphics;

  5. type
  6.   TCustomShapeControl = class(TGraphicControl)
  7.   protected
  8.     procedure Paint; override;
  9.   end;

  10. implementation

  11. procedure TCustomShapeControl.Paint;
  12. var
  13.   Rect: TRect;
  14. begin
  15.   Rect := ClientRect; // 获取控件的工作区域
  16.   Canvas.Brush.Color := clBlue; // 设置填充颜色为蓝色
  17.   Canvas.FillRect(Rect); // 使用当前画笔填充矩形
  18.   Canvas.Ellipse(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom); // 绘制圆形
  19. end;

  20. end.
复制代码
  1. uses
  2.   CustomShapeControl;

  3. procedure TForm1.FormCreate(Sender: TObject);
  4. var
  5.   CustomControl: TCustomShapeControl;
  6. begin
  7.   CustomControl := TCustomShapeControl.Create(Self);
  8.   CustomControl.Parent := Self;
  9.   CustomControl.SetBounds(10, 10, 100, 100); // 设置控件的位置和大小
  10. end;
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-4-16 04:25 , Processed in 0.015828 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表