在 delphi 中获取鼠标下方的类别按钮项目标题

get categorybuttons items caption under mouse in delphi

当鼠标进入某个项目或类别时,如何获取它们的标题? 右键单击项目或类别时如何获取它们的当前标题? 我为类别按钮分配了一个弹出菜单。现在我需要获取当前项目或类别标题并将它们保存在变量中。因为我的弹出菜单有一个项目,点击它会打开一个新表单,所以我想在这里使用这个变量值。

类似这样的东西在点击事件中起作用:

Current_Items, Current_Category: String

procedure TForm1.CategoryButtons1Click(Sender: TObject);
begin
  Current_Items := CategoryButtons1.CurrentCategory.Items
    [CategoryButtons1.SelectedItem.Index].Caption;
  Current_Category := CategoryButtons1.CurrentCategory.Caption;
end;

但我需要在右键时获取它们。 有人可以帮我做这个吗? 谢谢...

编辑:

使用 OnHotButton 事件准备 Current_Item 变量。这为您提供了单击鼠标右键的项目,但不是类别。

但请注意,这不会select(激活)那个特定按钮。

var
  Current_Items, Current_Category: String;

procedure TForm17.CategoryButtons1HotButton(Sender: TObject;
  const Button: TButtonItem);
begin
  if Button <> nil then
    Current_Items := Button.Caption;
end;

然后在弹出菜单的时候用Current_Items判断哪个按钮是hot