[翻译]Writing Custom Common Controls 编写自定义控件

摘要:介绍如何编写自定义的控件,用在报表的窗体上(如Edit,Button等)

 

Writing Custom Common Controls 编写自定义控件

FastReport contains a set of common controls which can be placed on dialogue forms inside reports. They are as follows:

FastReport包含以下控件,用于报表里的对话形式窗体。

TfrxLabelControl

TfrxEditControl

TfrxMemoControl

TfrxButtonControl

TfrxCheckBoxControl

TfrxRadioButtonControl

TfrxListBoxControl

TfrxComboBoxControl

TfrxDateEditControl

TfrxImageControl

TfrxBevelControl

TfrxPanelControl

TfrxGroupBoxControl

TfrxBitBtnControl

TfrxSpeedButtonControl

TfrxMaskEditControl

TfrxCheckListBoxControl

These controls correspond to the Delphi component palette standard controls. If the standard functionality is not sufficient then you can create your own common controls for use in your reports.

这些控件跟DELPHI标准控件一致,如果不能满足需求,可以自己编写控件。

The base class for all common controls is the “TfrxDialogControl” class, declared in the frxClass file:

(使用基类TfrxDialogControl)

TfrxDialogControl = class(TfrxReportComponent)

protected

procedure InitControl(AControl: TControl);

public

constructor Create(AOwner: TComponent); override;

destructor Destroy; override;

class function GetDescription: String; virtual;

property Caption: String;

property Color: TColor;

property Control: TControl;

property OnClick: TfrxNotifyEvent;

property OnDblClick: TfrxNotifyEvent;

property OnEnter: TfrxNotifyEvent;

property OnExit: TfrxNotifyEvent;

property OnKeyDown: TfrxKeyEvent;

property OnKeyPress: TfrxKeyPressEvent;

property OnKeyUp: TfrxKeyEvent;

property OnMouseDown: TfrxMouseEvent;

property OnMouseMove: TfrxMouseMoveEvent;

property OnMouseUp: TfrxMouseEvent;

published

property Left;

property Top;

property Width;

property Height;

property Font;

property ParentFont;

property Enabled: Boolean;

property Visible;

end;

 

To create your own control you should inherit from this class and override at least the constructor and the “GetDescription” method. It will be necessary to create the common control and initialize it using the “InitControl” method in the constructor. The GetDescription method is for returning a description of the common control. As you can see the TfrxDialogControl class already has a large number of properties and methods in the public section. Move properties and events into the “published” section of your common control as required and also create new properties that are specific to your control.

编写自定义的控件应该从类TfrxDialogControl继承,并至少要重写constructor 和GetDescription方法。

 

Common control registration and deletion is performed by using the frxObjects global object methods declared in the frxDsgnIntf file:

控件的注册和删除使用全局方法frxObjects,方法在frxDsgnIntf 文件中。

frxObjects.RegisterObject(ClassRef: TfrxComponentClass;ButtonBmp: TBitmap);

frxObjects.Unregister(ClassRef: TfrxComponentClass);

During registration you should specify the control class name and its picture. The ButtonBmp size should be 16x16 pixels.

在注册过程中,你应该指定控制类名称和它的图片。ButtonBmp的尺寸应为16X16像素。

 

Let‘s look at an example of a common control that simplifies the functionality of the standard Delphi TBitBtn control.

让我们编写一个简单的例子,实现标准的Delphi控件Tbitbtn功能。

uses frxClass, frxDsgnIntf, Buttons;

type

TfrxBitBtnControl = class(TfrxDialogControl)

private

FButton: TBitBtn;

procedure SetKind(const Value: TBitBtnKind);

function GetKind: TBitBtnKind;

public

constructor Create(AOwner: TComponent); override;

class function GetDescription: String; override;

property Button: TBitBtn read FButton;

published

{ add new properties }

property Kind: TBitBtnKind read GetKind write SetKind default bkCustom;

{ following properties are already declared in parent class }

property Caption;

property OnClick;

property OnEnter;

property OnExit;

property OnKeyDown;

property OnKeyPress;

property OnKeyUp;

property OnMouseDown;

property OnMouseMove;

property OnMouseUp;

end;

constructor TfrxBitBtnControl.Create(AOwner: TComponent);

begin

{ default constructor }

inherited;

{ create required common control }

FButton := TBitBtn.Create(nil);

FButton.Caption := ‘BitBtn‘;

{ initialize it }

InitControl(FButton);   //初始化对象

{ set default size }

Width := 75;

Height := 25;

end;

class function TfrxBitBtnControl.GetDescription: String;

begin

Result := ‘BitBtn control‘;

end;

procedure TfrxBitBtnControl.SetKind(const Value: TBitBtnKind);

begin

FButton.Kind := Value;

end;

function TfrxBitBtnControl.GetKind: TBitBtnKind;

begin

Result := FButton.Kind;

end;

//注册

var

Bmp: TBitmap;

initialization

Bmp := TBitmap.Create;

{ load picture from resource;

it should have already been placed there, of course }

Bmp.LoadFromResourceName(hInstance, ‘frxBitBtnControl‘);

frxObjects.RegisterObject(TfrxBitBtnControl, Bmp);

finalization

frxObjects.Unregister(TfrxBitBtnControl);

Bmp.Free;

end.

时间: 2024-08-24 20:48:31

[翻译]Writing Custom Common Controls 编写自定义控件的相关文章

Windows Common Controls

Win32 API中本身提供了Windows下许多常用的控件,称为Common Controls. 这些控件与Button.ComboBox等控件不同,不是在user32.dll中实现,而是在Comctrl32.dll中实现,相关的C++原型声明在commctrl.h中. 所以,在使用Win32 API编写Windows窗口应用程序时,如果在界面上用到了Common Controls,则必须在链接选项中包含comctrl32.lib库,并在程序初始化时调用InitCommonControls()

DevExpress 控件使用笔记 - Common Controls

这段时间一直在研究DevExpress控件库,本文是我对DevExpress工具箱中分类"DX.13.1: Common Controls"下控件的使用笔记.这个类型的控件都在DevExpress.XtraEditors.v13.1.dll中定义. 分类"DX.13.1: Common Controls"下控件列表如下: 针对以上控件,我选了一些做了笔记,内容如下: 1)ColorPickEdit,颜色选择控件,类似VS中控件属性管理器中的颜色选择工具,包括自定义.

(译)Getting Started——1.3.4 Writing a Custom Class(编写自定义的类)

 在开发IOS应用中,当你编写自定义的类时,你会发现很多的特殊场合.当你需要把自定义的行为和数据包装在一起时,自定义的类非常有用.在自定义的类中,你可以定义自己的存储.处理和显示数据的方法. 例如,IOS Clock应用中的World Clock面板.table view中的单元格需要显示比标准table view单元格更多的显示内容.这就是一个很好的机会来实现一个继承了UITableViewCell类的子类,用于在给定的table view单元格中显示更多的自定义内容.如果你正在设计自定义的类

Delphi编写自定义控件以及接口的使用(做了一个TpgDbEdit)

写给觉得自己编写Delphi很复杂的人,包括自己. Delphi自己写控件其实并不难,难的在于开发复杂的控件.(其实,编程,很多东西都是会了就不难,因此,我怕自己日后觉得自己写控件很难,特意在这记录自己写控件的过程,顺便也写下接口的使用) 第一步:控件代码: 下面是控件的一个Unit内容: 代码 unit pgdbedit; interface uses  SysUtils, Classes, Controls, StdCtrls, CnEdit; const  IID_pgDBConInter

WPF利用依赖属性和命令编写自定义控件

以实例讲解(大部分讲解在代码中) 1,新建一个WPF项目,添加一个用户控件之后在用户控件里面添加几个控件用作测试, <UserControl x:Class="SelfControlDenpendy.SelfControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006

Qt编写自定义控件插件开放动态库dll使用(永久免费)

这套控件陆陆续续完善了四年多,目前共133个控件,除了十几个控件参考网友开源的代码写的,其余全部原创,在发布之初就有打算将动态库开放出来永久免费使用,在控件比较完善的今天抽了半天时间编译了多个qt版本的动态库,和头文件一起打包放在百度网盘. 控件介绍 超过130个精美控件,涵盖了各种仪表盘.进度条.进度球.指南针.曲线图.标尺.温度计.导航条.导航栏,flatui.高亮按钮.滑动选择器.农历等.远超qwt集成的控件数量. 每个类都可以独立成一个单独的控件,零耦合,每个控件一个头文件和一个实现文件

Qt编写自定义控件5-柱状温度计

前言 柱状温度计控件,可能是很多人练手控件之一,基本上都是垂直方向展示,底部一个水银柱,中间刻度尺,刻度尺可以在左侧右侧或者两侧都有,自适应分辨率改动,有时候为了美观效果,可能还会整个定时器来实现动画效果,开启动画效果的缺点就是CPU占用会比较高,前阵子有个好友(贾文涛-涛哥)向我推荐了一个opengl绘制的开源东西,QNanoPainter,东西是个好东西,我个人的理解是直接封装了opengl绘制的qpainter,可以使得绘制全部走GPU,这样就可以大大减轻CPU的负担,非常方便,我自己试了

Qt编写自定义控件13-多态进度条

前言 多态进度条,顾名思义,有多重状态,其实本控件主要是用来表示百分比进度的,由于之前已经存在了百分比进度条控件,名字被霸占了,按照先来先得原则,只好另外取个别名叫做多态进度条,应用场景是,某种任务有三种状态,比如正常状态.警戒状态.报警状态,这三种状态都分别有一个占比,需要用不同的颜色表示,这样就衍生出了此控件,类似于堆积图.接下来节假日四天,可以全身心投入研发还未完工的大屏UI程序,基础控件部分+二级界面部分都已经做好,现在专心整合到主界面和打通数据流(采用数据库采集+网络采集两种方式).多

Qt编写自定义控件14-环形进度条

前言 环形进度条,用来展示当前进度,为了满足大屏UI的需要特意定制,以前有个叫圆环进度条,不能满足项目需要,只能重新定做,以前的进度间距不能自适应分辨率,而且当前进度对应的反的进度不能单独设置颜色,即当前进度90%,剩余的10%也需要设置成不同的颜色,还有一个重要的功能是,能够指定多个警戒值,一旦超过或者小于该值,则当前进度自动切换到预先设定的警戒值颜色,而不需要用户自己去判断警戒值去设置警戒颜色,用户只需要传入当前值即可,这个功能非常实用,还可以设置警戒判断的标准是超过值还是小于值报警.个人感