Показать сообщение отдельно
  #14  
Старый 26.09.2011, 11:31
Аватар для NumLock
NumLock NumLock вне форума
Let Me Show You
 
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
По умолчанию

Код:
unit EditButtonControl;

interface

uses
  StdCtrls,
  Windows, Messages, SysUtils, Classes, Graphics, Controls;

type
  TEditButtonControl = class(TCustomControl)
  private
    FEdit: TEdit;
    FButton: TButton;
    FOnClick: TNotifyEvent;
    procedure OnButtonClick(Sender: TObject);
  protected
    procedure Paint; override;
    procedure SetParent(AParent: TWinControl); override;
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  published
    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.Create(Self);
  FButton:=TButton.Create(Self);
  FButton.Caption:='Click me...';
  FButton.OnClick:=OnButtonClick;
end;

destructor TEditButtonControl.Destroy;
begin
//  if Assigned(FEdit) then FEdit.Free;
//  if Assigned(FButton) then FButton.Free;
  inherited Destroy;
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);
end;

procedure TEditButtonControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
  AWidth:=200;
  AHeight:=76;
  if Assigned(FEdit) then
  begin
    FEdit.Left:=ALeft+10;
    FEdit.Top:=ATop+10;
    if Assigned(FButton) then
    begin
      FButton.Left:=ALeft+10;
      FButton.Top:=ATop+10+FEdit.Height+10;
    end;
  end;
  inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;

procedure TEditButtonControl.SetParent(AParent: TWinControl);
begin
  inherited SetParent(AParent);
  if Assigned(FEdit) then FEdit.Parent:=AParent;
  if Assigned(FButton) then FButton.Parent:=AParent;
end;

procedure TEditButtonControl.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (AComponent=FEdit) and (Operation=opRemove) then FEdit:=nil;
  if (AComponent=FButton) and (Operation=opRemove) then FButton:=nil;
end;

procedure TEditButtonControl.OnButtonClick(Sender: TObject);
begin
  Windows.Beep(1000, 10);
end;

end.
__________________
Пишу программы за еду.
__________________
Ответить с цитированием