希望好心的同志予以指点,在此先谢过了(50分)

  • 主题发起人 主题发起人 anita
  • 开始时间 开始时间
A

anita

Unregistered / Unconfirmed
GUEST, unregistred user!
因为刚刚学delphi,所以一切还不是很熟悉,希望好心的同志予以指点,在此先谢过了。请好心的同志把下面的程序注释一下,以便让我理解,再次谢过。
unit ColorButton;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;

type
TDrawButtonEvent = procedure(Control: TWinControl;
Rect: TRect
State: TOwnerDrawState) of object;

TColorButton = class(TButton)
private
FCanvas: TCanvas;
IsFocused: Boolean;
FOnDrawButton: TDrawButtonEvent;
protected
procedure CreateParams(var Params: TCreateParams)
override;
procedure SetButtonStyle(ADefault: Boolean)
override;
procedure CMEnabledChanged(var Message: TMessage)
message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage)
message CM_FONTCHANGED;
procedure CNMeasureItem(var Message: TWMMeasureItem)
message CN_MEASUREITEM;
procedure CNDrawItem(var Message: TWMDrawItem)
message CN_DRAWITEM;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk)
message WM_LBUTTONDBLCLK;
procedure DrawButton(Rect: TRect
State: UINT);
public
constructor Create(AOwner: TComponent)
override;
destructor Destroy
override;
property Canvas: TCanvas read FCanvas;
published
property OnDrawButton: TDrawButtonEvent read FOnDrawButton write FOnDrawButton;
property Color;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('MyVcl', [TColorButton]);
end;
 
不喜欢! 你不如直接说哪里不懂得了,我们又不是廉价劳动力
 
unit ColorButton
//单元名称为 ColorButton

interface

uses //引用到的单元
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;

type
//自定义的一个事件类型 TDrawButtonEvent
TDrawButtonEvent = procedure(Control: TWinControl;
Rect: TRect
State: TOwnerDrawState) of object;

//从TButton继承的ColorButton
TColorButton = class(TButton)
private
FCanvas: TCanvas
//画布(估计可能是用来画不同状态时候的不同颜色的)
IsFocused: Boolean
//是不是得到焦点
FOnDrawButton: TDrawButtonEvent
//定义一个 TDrawButtonEvent类型的事件
protected
//过载TWinControl.CreateParams过程,初始化组件的参数
procedure CreateParams(var Params: TCreateParams)
override;

//设置Button组件风格 既是 BS_PUSHBUTTON 或者 BS_DEFPUSHBUTTON ;
procedure SetButtonStyle(ADefault: Boolean)
override;

//以下都是Button组件 在一些事件和属性改变中触发的消息过程
procedure CMEnabledChanged(var Message: TMessage)
message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage)
message CM_FONTCHANGED;
procedure CNMeasureItem(var Message: TWMMeasureItem)
message CN_MEASUREITEM;
procedure CNDrawItem(var Message: TWMDrawItem)
message CN_DRAWITEM;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk)
message WM_LBUTTONDBLCLK;
procedure DrawButton(Rect: TRect
State: UINT);
public
//以下是 创建、销毁过程 公布了画布属性
constructor Create(AOwner: TComponent)
override;
destructor Destroy
override;
property Canvas: TCanvas read FCanvas;
published
//对外公布 TDrawButtonEvent 类型的 OnDrawButton事件,使用户可以在这个事件里面写出自己的处理
property OnDrawButton: TDrawButtonEvent read FOnDrawButton write FOnDrawButton;
property Color;
end;

procedure Register;

implementation

procedure Register;
begin //注册这个组件到MyVCL面板当中
RegisterComponents('MyVcl', [TColorButton]);
end;
 
呀~! 感情我成了廉价劳动力了! :( 哈哈哈哈哈
 
接受答案了.
 
宁柯說得好,說的對1
 
后退
顶部