Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VCL control based + additionnal control...

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,

I'm building a new VCL based on TListBox control. I want to add a 'Caption' property which will use an additionnal BitBtn control on top of the ListBox (that is, to simulate a grid column's header).

Is there anyway to build a VCL which integrates 2 different controls?

Thanks for reply,

PS Second sending because the problem was not solved... :)
 
Yep. That's no problems...

Derive your new control from TCustomPanel, and programatically add the Listbox and the TBitbutton on your control.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
Hi there again.

Here you got a snippet. No fancy things added...

Code:
unit MyListbox;

interface

uses
  SysUtils, Classes, Controls, ExtCtrls, StdCtrls;

type
  TMyListbox = class(TCustomPanel)
  private
    FListbox: TListbox;
    FButton: TButton;
    function GetItems: TStrings;
    procedure SetItems(const Value: TStrings);
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Items: TStrings read GetItems write SetItems;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyListbox]);
end;

{ TMyListbox }

constructor TMyListbox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  BevelOuter := bvNone;

  FButton := TButton.Create(nil);
  with FButton do
  begin
    Height := 21;

    Align := alTop;
    Parent := self;
  end;

  FListbox := TListbox.Create(nil);
  with FListbox do
  begin
    Align := alClient;
    Parent := self;
  end;
end;

destructor TMyListbox.Destroy;
begin
  FListbox.Free;
  FButton.Free;
  inherited;
end;

function TMyListbox.GetItems: TStrings;
begin
  Result := Flistbox.Items;
end;

procedure TMyListbox.SetItems(const Value: TStrings);
begin
  FListbox.Items := Value;
end;

end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top