如何使用下拉菜单创建按钮?

时间:2022-04-22 13:14:02

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

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

4 个解决方案

#1


10  

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.

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

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:

示例:在表单上删除任何带有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;

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.

注意:如果您想要延迟,则在另一个方法中提取该代码,然后设置一个计时器OnClick并转动OnMouseLeave的计时器。然后,如果计时器触发,您可以调用提取的方法。不知道如何在键盘上点击它。我不知道Firefox等是否也支持。

#2


8  

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:

吉姆的答案很棒,但起初并不适合我。 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;

This works no matter where the button is.

无论按钮在哪里,这都有效。

#3


7  

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.

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

#4


1  

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.

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

#1


10  

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.

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

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:

示例:在表单上删除任何带有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;

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.

注意:如果您想要延迟,则在另一个方法中提取该代码,然后设置一个计时器OnClick并转动OnMouseLeave的计时器。然后,如果计时器触发,您可以调用提取的方法。不知道如何在键盘上点击它。我不知道Firefox等是否也支持。

#2


8  

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:

吉姆的答案很棒,但起初并不适合我。 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;

This works no matter where the button is.

无论按钮在哪里,这都有效。

#3


7  

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.

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

#4


1  

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.

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