主要是想做一个和QQ差不多的Bar,FORM上只有一个PANEL1控件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ToolWin, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure abc(HeaderControl: THeaderControl;
Section: THeaderSection);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.abc(HeaderControl: THeaderControl;
Section: THeaderSection);
var j:integer;
k:integer;
i:integer;
o:integer;
s:string;
pp:theadercontrol;
begin
j:=strtoint(copy(HeaderControl.Name,length(headercontrol.Name),1));
for i:=1 to j do //向上的
begin
pp:=Theadercontrol(panel1.FindComponent('bar'+inttostr(i)));
pp.align:=altop;
end;;
o:=0;
for i:=0 to panel1.ControlCount-1 do
if panel1.Controls.ClassType=THeaderControl then
o:=o+1;
for k:=j+1 to o do //向下的
begin
showmessage('PanelB'+inttostr(k));
end;
showmessage('panela'+inttostr(j))
//当前的
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:theadercontrol;
k:THeaderSection;
j:integer;
p:tpanel;
begin
for j:=1 to 5 do
begin
i:=THeaderControl.Create(nil);
k:=THeaderSection.Create(nil);
i.OnSectionClick:=abc;
i.Parent:=panel1;
i.Name:='Bar'+inttostr(j);
k.Width:=panel1.Width-1;
k.Text:=i.Name;
k.Alignment:=taCenter;
k.MaxWidth:=k.Width;
k.MinWidth:=k.Width;
i.Sections.AddItem(k,0);
i.Cursor:=crArrow;
p:=tpanel.Create(nil);
p.Parent:=panel1;
p.Name:='panel'+inttostr(j);
p.Caption:=p.Name;
p.Width:=panel1.Width;
p.Height:=100;
p.Align:=albottom;
end;
end;
end.