unit EditButtonControl;
interface
uses
// Dialogs,
Windows, Messages, SysUtils, Classes, Graphics, Controls;
type
TEditButtonControl = class(TCustomControl)
private
FEdit: String;
FButton: String;
FOnClick: TNotifyEvent;
procedure SetEdit(const Value: String);
procedure SetButton(const Value: String);
protected
procedure Paint; override;
procedure WMLButtonDown(var Message: TWMLButtonDown);
message WM_LBUTTONDOWN;
public
constructor Create(AOwner: TComponent); override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
published
property Edit: String read FEdit write SetEdit;
property Button: String read FButton write SetButton;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Internet', [TEditButtonControl]);
end;
{ TEditButtonControl }
constructor TEditButtonControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEdit:='TEdit';
FButton:='TButton';
end;
procedure TEditButtonControl.Paint;
var
ARect: TRect;
begin
Canvas.Brush.Color:=clBtnFace;
Canvas.FillRect(ClientRect);
ARect:=Rect(0, 0, Width, Height);
DrawEdge(Canvas.Handle, ARect, EDGE_RAISED, BF_RECT);
ARect:=Rect(10, 10, Width-10, 10+21);
Canvas.Brush.Color:=clWindow;
Canvas.FillRect(ARect);
DrawEdge(Canvas.Handle, ARect, EDGE_SUNKEN, BF_RECT);
InflateRect(ARect, -4, 0);
DrawText(Canvas.Handle, PChar(FEdit), -1, ARect,
DT_LEFT or DT_SINGLELINE or DT_VCENTER);
ARect:=Rect(10, 10+21+10, 10+75, 10+21+10+25);
Canvas.Brush.Color:=clBtnFace;
Canvas.FillRect(ARect);
DrawEdge(Canvas.Handle, ARect, EDGE_RAISED, BF_RECT);
DrawText(Canvas.Handle, PChar(FButton), -1, ARect,
DT_CENTER or DT_SINGLELINE or DT_VCENTER);
end;
procedure TEditButtonControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
AWidth:=200;
AHeight:=76;
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;
procedure TEditButtonControl.WMLButtonDown(var Message: TWMLButtonDown);
begin
inherited;
if (Message.XPos>=10) and (Message.XPos<=85) and (Message.YPos>=10+21+10)
and (Message.YPos<=10+21+10+25) then
begin
if Assigned(FOnClick) then FOnClick(Self);
// Edit:=InputBox('InputBox', 'Text:', '');
end;
end;
procedure TEditButtonControl.SetEdit(const Value: String);
begin
if Value<>FEdit then
begin
FEdit:=Value;
Invalidate;
end;
end;
procedure TEditButtonControl.SetButton(const Value: String);
begin
if Value<>FButton then
begin
FButton:=Value;
Invalidate;
end;
end;
end.