我想写一个组件,在EDIT组件上加一个按钮,应怎写?(100分)

  • 主题发起人 主题发起人 kevenzhang
  • 开始时间 开始时间
K

kevenzhang

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位高手告诉我
 
组合
{*******************************************************}
{ }
{ 带按钮的edit }
{ 作者:宋永政 }
{ E-mail:antic_ant@hotmail.com }
{ http://antic_ant.delphibbs.com }
{ 日期:2002-06-22 }
{ }
{ }
{*******************************************************}
unit Eliedit;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, Menus;

type
TElipsisEdit = class(TCustomMemo)
private
{ Private declarations }
protected
{ Protected declarations }
FElipsis: TSpeedButton;
function GetOnClick: TNotifyEvent;
procedure SetOnClick(Value: TNotifyEvent);
procedure UpdateFormatRect;
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
procedure CMEnabledChanged(var Msg: TWMNoParams);
message CM_ENABLEDCHANGED;
procedure CreateHandle; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property Align;
property Alignment;
property AutoSelect;
property AutoSize;
property BorderStyle;
property CharCase;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;

property OnElipsisClick: TNotifyEvent read GetOnClick write SetOnClick;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('syz_component', [TElipsisEdit]);
end;

constructor TElipsisEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height := 24;
Width := 150;
WordWrap := False;
WantReturns := False;

FElipsis := TSpeedButton.Create(Self);
with FElipsis do
begin
Parent := Self;
Align := alRight;
Caption := '...';
end;
end;

procedure TElipsisEdit.CreateHandle;
begin
inherited CreateHandle;
UpdateFormatRect;
end;

function TElipsisEdit.GetOnClick: TNotifyEvent;
begin
Result := FElipsis.OnClick;
end;

procedure TElipsisEdit.SetOnClick(Value: TNotifyEvent);
begin
FElipsis.OnClick := Value;
end;

procedure TElipsisEdit.UpdateFormatRect;
var
Rect: TRect;
begin
Rect := ClientRect;
Dec(Rect.Right, FElipsis.Width);
SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Rect));
end;

procedure TElipsisEdit.WMSize(var Msg: TWMSize);
begin
inherited;
FElipsis.Width := FElipsis.Height;
UpdateFormatRect;
end;

procedure TElipsisEdit.WMSetCursor(var Msg: TWMSetCursor);
var
P: TPoint;
begin
GetCursorPos(P);
P := ScreenToClient(P);
if (P.X >= ClientWidth - FElipsis.Width) then
SetCursor(Screen.Cursors[crDefault])
else
inherited;
end;

procedure TElipsisEdit.CMEnabledChanged(var Msg: TWMNoParams);
begin
inherited;
FElipsis.Enabled := Enabled;
end;

end.
 
现在的人写代码越少越要注释了。
这种组合的组件,可以参考一下TLabelEdit,其中有个很重要的方法SetSubComponent
 
请问有没有现成的EDIT控件可以使用呀?EDIT带按钮。
 
对哦,没有注释不容易看懂,比较费劲。
 
to antic_ant
我把edit改为平面的,按钮周围会出现一圈白边2个点,怎样让白边消除掉!!
 
后退
顶部