unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.CategoryButtons, Vcl.StdCtrls;
type
TForm1 = class(TForm)
CategoryButtons1: TCategoryButtons;
procedure CategoryButtons1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
function FindButtonFocused(nFindType: Integer; CategoryButtons: TCategoryButtons): TBaseItem;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.FindButtonFocused(nFindType: Integer; CategoryButtons: TCategoryButtons): TBaseItem;
var
p: TPoint;
x,y: Integer;
Category: TButtonCategory;
Item: TButtonItem;
begin
Result := nil;
GetCursorPos(p);
p:=ScreenToClient(p);
x := p.X-CategoryButtons.Left;
y := p.Y-CategoryButtons.Top;
if nFindType = 1 then
begin
Item := CategoryButtons.GetButtonAt(x,y,nil);
if Item <>nil then
Result := TBaseItem(Item);
end else begin
Category := CategoryButtons.GetCategoryAt(x,y);
if Category <>nil then
Result := TBaseItem(Category);
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
CategoryButtons1.BorderStyle := bsNone;
end;
procedure TForm1.CategoryButtons1Click(Sender: TObject);
var
BaseItem:TBaseItem;
Item: TButtonItem;
Category: TButtonCategory;
lv_sMsg: string;
begin
//第1步 TButtonCategory
BaseItem := FindButtonFocused(0,CategoryButtons1);
if (BaseItem <> nil) and (BaseItem is TButtonCategory) then
begin
Category := TButtonCategory(BaseItem);
lv_sMsg := '点击的是第' + IntToStr(Category.Index) + '个ButtonCategory哟!' + #13;
ShowMessage(lv_sMsg);
end else begin
ShowMessage('没找到哟!');
end;
end;
end.