unit DBButtonEdit;
interface
uses
Windows, SysUtils, Classes, Controls, Messages, StdCtrls, Mask, DBCtrls,
Buttons;
type
TDBButtonEdit = class(TDBEdit)
private
FButton: TSpeedButton;
function GetOnButtonClick: TNotifyEvent;
procedure SetOnButtonClick(const Value: TNotifyEvent);
procedure SetEditRect;
protected
procedure CreateParams( var Params: TCreateParams ); override;
procedure CreateWnd; override;
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure CMEnter(var Msg: TCMEnter); message CM_ENTER;
procedure CMExit(var Msg: TCMExit); message CM_EXIT;
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
property Button: TSpeedButton read FButton;
property OnButtonClick: TNotifyEvent read GetOnButtonClick write SetOnButtonClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TDBButtonEdit]);
end;
{ TDBButtonEdit }
procedure TDBButtonEdit.CMEnabledChanged(var Msg: TMessage);
begin
SetEditRect;
end;
procedure TDBButtonEdit.CMEnter(var Msg: TCMEnter);
begin
SetEditRect;
end;
procedure TDBButtonEdit.CMExit(var Msg: TCMExit);
begin
SetEditRect;
end;
procedure TDBButtonEdit.CMFontChanged(var Msg: TMessage);
begin
SetEditRect;
end;
constructor TDBButtonEdit.Create(Owner: TComponent);
begin
inherited;
FButton := TSpeedButton.Create(Self);
FButton.Parent := Self;
FButton.Cursor := crArrow;
end;
procedure TDBButtonEdit.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_CLIPCHILDREN;
end;
procedure TDBButtonEdit.CreateWnd;
begin
inherited;
SetEditRect;
end;
destructor TDBButtonEdit.Destroy;
begin
FButton.Free;
inherited;
end;
function TDBButtonEdit.GetOnButtonClick: TNotifyEvent;
begin
Result := FButton.OnClick;
end;
procedure TDBButtonEdit.SetEditRect;
begin
if not UseRightToLeftAlignment then
begin
SendMessage(Handle, EM_SETMARGINS, EC_LEFTMARGIN, 0);
SendMessage(Handle, EM_SETMARGINS, EC_RIGHTMARGIN, MakeLong(0, Height + 2));
end
else
begin
SendMessage(Handle, EM_SETMARGINS, EC_LEFTMARGIN, MakeLong(Height + 2, 0));
SendMessage(Handle, EM_SETMARGINS, EC_RIGHTMARGIN, 0 );
end;
end;
procedure TDBButtonEdit.SetOnButtonClick(const Value: TNotifyEvent);
begin
FButton.OnClick := Value;
end;
procedure TDBButtonEdit.WMSize(var Msg: TWMSize);
begin
if Assigned(FButton) then
begin
if Ctl3D then
FButton.SetBounds(Width - Height, 0, (Height - 4), (Height - 4))
else
FButton.SetBounds(Width - Height + 1, 1, Height - 1, Height - 1);
end;
end;
end.
似乎有点问题,单击Edit框多次为什么Button会不刷新?