delphi xe QQ式分类按钮 CategoryPanelGroup1

 

 object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 595
  ClientWidth = 945
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object CategoryPanelGroup1: TCategoryPanelGroup
    Left = 0
    Top = 0
    Height = 595
    VertScrollBar.Tracking = True
    HeaderFont.Charset = DEFAULT_CHARSET
    HeaderFont.Color = clWindowText
    HeaderFont.Height = -11
    HeaderFont.Name = 'Tahoma'
    HeaderFont.Style = []
    TabOrder = 0
    ExplicitHeight = 323
  end
  object Memo1: TMemo
    Left = 206
    Top = 1
    Width = 731
    Height = 602
    Lines.Strings = (
      'Memo1')
    TabOrder = 1
  end
end

 

delphi xe QQ式分类按钮 CategoryPanelGroup1

代码如下:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,
  System.ImageList, Vcl.ImgList;

type
  TForm1 = class(TForm)
    CategoryPanelGroup1: TCategoryPanelGroup;
    ImageList1: TImageList;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure buttonclick(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure  TForm1.buttonclick(Sender: TObject);
var
qrstring:string;
 begin
    memo1.Lines.Clear;
   qrstring:='select  *  from employees where Employeeid=';
   qrstring:=qrstring+Tbutton(sender).Caption;
   memo1.Lines.add(qrstring);

 end;

procedure TForm1.FormCreate(Sender: TObject);
var catPanel: TCategoryPanel;
  x: word;
 btn:TButton;
  i:integer;
 b:TComponent;
begin
  x := 0;
  while x < 4 do
  begin
    catPanel := CategoryPanelGroup1.CreatePanel(Self) as TCategoryPanel;
    catPanel.Height:=125; //只有在这个位置才OK
    catPanel.Collapsed:=true;
    catPanel.PanelGroup := CategoryPanelGroup1;

    catPanel.Caption := '部门'+x.ToString ;
    for i := 1  to 4 do
    begin
     btn:=TButton.Create(nil);
     btn.Parent:=catPanel;
     btn.Name:='TButton'+inttostr(x)+inttostr(i);
     btn.align:=altop;
     btn.Caption:='员工'+inttostr(x)+inttostr(i);
     btn.Height:=25;
     btn.Top:=25*i ;
     btn.onClick:=buttonclick;


    end;

    i:=0;
    Inc(x);
  end; //loop
end;

{procedure zapPanels(sender : tobject);
var
idx : integer;
x : tCategoryPanel;
begin
for idx := ((sender as tCategoryPanelGroup).Panels.Count)-1 downto 0 do
  begin
  x := (sender as tCategoryPanelGroup).Panels.Items[idx];
  x.Destroy;
  end;
end;}


end.