组合
{*******************************************************}
{ }
{ 带按钮的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.