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;
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;