如何创建带有下拉菜单的按钮?

发布于 2024-07-07 12:03:45 字数 40 浏览 6 评论 0原文

有没有办法显示 IE/Firefox 后退按钮样式、下拉菜单按钮?

Is there a way to show IE/Firefox Back button style, dropdown menu button?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤独患者 2024-07-14 12:03:45

当然。 在页面上放置一个工具栏。 右键单击工具栏,添加按钮。 将按钮的样式设置为 tbsDropDown。 在页面上放置一个弹出菜单。 双击 PopupMenu 来定义菜单项。 然后,返回到您创建的按钮并将其 DropdownMenu 属性设置为指向您刚刚创建的 PopupMenu。

Sure. Put a toolbar on the page. Right-click on the toolbar, add a button. Set the button's style to tbsDropDown. Put a PopupMenu on the page. Double click on the PopupMenu to define menu items. Then, go back to the button you created and set its DropdownMenu property to point to the PopupMenu you just created.

许仙没带伞 2024-07-14 12:03:45

我假设您的意思是单击时会下拉菜单的按钮。

您也可以手动编码按钮单击以在其下方下拉 TPopupMenu。

示例:在表单上放置带有 TClickEvent(可能是 TButton)和 TPopupMenu 的任何内容。 添加一些菜单项。 然后添加以下 OnClick 事件处理程序:

procedure TForm86.Button1Click(Sender: TObject);
var
  button: TControl;
  lowerLeft: TPoint;
begin
  if Sender is TControl then
  begin
    button := TControl(Sender);
    lowerLeft := Point(button.Left, button.Top + Button.Height);
    lowerLeft := ClientToScreen(lowerLeft);
    PopupMenu1.Popup(lowerLeft.X, lowerLeft.Y);
  end;
end;

还有中提琴! 就像魔法一样。 如果您打算重用它,您可以将其全部包装在一个组件中。 甚至可能在线出售。

注意:如果您想要延迟,请在另一个方法中提取该代码,然后设置一个计时器 OnClick 并打开 OnMouseLeave 计时器。 然后,如果计时器触发,您可以调用提取的方法。 不知道如何通过点击键盘来完成此操作。 我也不知道Firefox等是否支持。

I am assuming you mean a button that drops down a menu when clicked.

You can also just manually code your button click to drop down a TPopupMenu under it.

Example: Drop anything with a TClickEvent (maybe a TButton) and a TPopupMenu on your form. Add some menu items. Then add the following OnClick event handler:

procedure TForm86.Button1Click(Sender: TObject);
var
  button: TControl;
  lowerLeft: TPoint;
begin
  if Sender is TControl then
  begin
    button := TControl(Sender);
    lowerLeft := Point(button.Left, button.Top + Button.Height);
    lowerLeft := ClientToScreen(lowerLeft);
    PopupMenu1.Popup(lowerLeft.X, lowerLeft.Y);
  end;
end;

And viola! Just like magic. You could wrap it all up in a component if you plan to reuse it. Maybe even sell it online.

Note: If you want a delay, then extract that code in another method and then set a timer OnClick and turn the timer of OnMouseLeave. Then if the timer fires you can call the extracted method. Not sure how you would do it on a keyboard click. I don't know if Firefox, etc. supports that either.

苍景流年 2024-07-14 12:03:45

吉姆的回答很好,但一开始对我来说不太有效。 ClientToScreen 使用 Form86 的方法,只有当按钮直接位于表单上时,该方法才是正确的。 应该调用按钮的 ClientToScreen 方法,如下所示:

procedure TForm86.Button1Click(Sender: TObject);
var
  button: TControl;
  lowerLeft: TPoint;
begin
  if Sender is TControl then
  begin
    button := TControl(Sender);
    lowerLeft := Point(0, button.Height);
    lowerLeft := button.ClientToScreen(lowerLeft);
    PopupMenu1.Popup(lowerLeft.X, lowerLeft.Y);
  end;
end;

无论按钮位于何处,该方法都有效。

Jim's answer is great, but didn't quite work for me at first. ClientToScreen uses Form86's method, which is only correct if the button is directly on the form. It should be the button's ClientToScreen method that is called, like this:

procedure TForm86.Button1Click(Sender: TObject);
var
  button: TControl;
  lowerLeft: TPoint;
begin
  if Sender is TControl then
  begin
    button := TControl(Sender);
    lowerLeft := Point(0, button.Height);
    lowerLeft := button.ClientToScreen(lowerLeft);
    PopupMenu1.Popup(lowerLeft.X, lowerLeft.Y);
  end;
end;

This works no matter where the button is.

耀眼的星火 2024-07-14 12:03:45

如果您不想使用工具栏,则 Raize (www.raize.com) 和 Express 编辑器 (www.DevExpress.com) 库具有可以执行此操作的组件。

If you don't want to use a toolbar, the raize (www.raize.com) and express editors (www.DevExpress.com) libraries have components that can do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文