效果图
![](http://delphi.ktop.com.tw/loadfile.php?TOPICID=11755354&CC=262906)
使用:
procedure TForm1.FormCreate(Sender: TObject);
begin
BCB1.combobox.Items.Add('sos_admin');
BCB1.combobox.Items.Add('sos_admin2');
BCB1.combobox.ItemIndex :=0;
BCB1.button.Caption :='...';
BCB1.Caption :=''; BCB2.combobox.Items.Add('sos_admin');
BCB2.combobox.Items.Add('sos_admin2');
BCB2.combobox.ItemIndex :=0;
BCB2.button.Caption :='...';
BCB2.Caption :='';
end; procedure TForm1.BCB1
buttonclick(Sender: TObject);
begin
showmessage('您好,bcb1:我是button');
end; procedure TForm1.BCB2buttonclick(Sender: TObject);
begin
showmessage('您好,bcb2:我是button');
end; 控件源码[bcb.pas] unit BCB; interface uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,
StdCtrls; type
TBCB = class(TPanel)
private
Fcombobox:Tcombobox;
Fbutton:Tbutton;
FOnbuttonclick: TNotifyEvent;
procedure buttonclick(sender:TObject);//作为按钮的事件
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
property button:Tbutton read Fbutton write Fbutton;
property combobox:Tcombobox read Fcombobox write Fcombobox;
property Onbuttonclick: TNotifyEvent read FOnbuttonclick write FOnbuttonclick;
{ Published declarations }
end; procedure Register; implementation procedure Register;
begin
RegisterComponents('BCB', [TBCB]);
end; constructor TBCB.Create(AOwner: TComponent);
begin
inherited;
Fcombobox := Tcombobox.Create (Self); Fcombobox.Parent:=self;
Fcombobox.Visible :=true;
Fcombobox.Left :=0;
Fcombobox.Top :=0; Fbutton:=Tbutton.Create(self);
Fbutton.Parent :=self;
Fbutton.Visible :=true;
Fbutton.Left :=Fcombobox.Width+Fcombobox.Left;
Fbutton.Top:= Fcombobox.Top ;
Fbutton.Height:=20 ;
Fbutton.Width :=20;
Fbutton.OnClick :=buttonclick; end; procedure tbcb.buttonclick(sender:TObject);
begin
if Assigned(FOnbuttonclick) then
FOnbuttonclick(sender);
end; destructor TBCB.Destroy;
begin
if Fbutton<>nil then Fbutton.Free ;
if Fcombobox<>nil then Fcombobox.Free ; inherited;
end; end.