当前位置: 首页 > 图文教程 > 开发语言 > Delphi > Delphi自定义部件开发(四)
19.3.2 创建图形部件
图形控制是一类简单的部件。因为纯图形部件从不需要得到键盘焦点,所以它没有也不要窗口句柄。包含图形控制的应用程序用户仍然可以用鼠标操作控制,但没有键盘界面。
在本例中提供的图形部件是TShape。Shape部件位于Component Palette的Additional页。本例中的Shape部件有所不同,因此称其为TSampleShape。
创建图形部件需要下列三个步骤:
● 创建和注册部件
● 公布(publishing)继承的属性
● 增加图形功能
19.3.2.1 创建和注册部件
每个部件的创建都从相同的方式开始,在本例中如下:
● 建立名为Shapes的部件单元
● 从TGraphicControl 继承,将新部件称为TSampleShape
● 在Component Palette的Samples页上注册TSampleShape
unit Shapes
intertace
use SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics,Controls,Forms;
type
TSampleShape=class(TGraphicControl)
end;
implementation
procedure Register;
begin
RegisterComponents('Samples',[TSampleShape]);
end;
评论 (0) All