如何创建下拉菜单按钮? [英] How to create a button with drop-down menu?

查看:182
本文介绍了如何创建下拉菜单按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,以显示IE / Firefox的后退按钮样式,下拉菜单按钮?

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

推荐答案

我假设你的意思是一个按钮,下拉点击时的菜单。

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

您也可以只手动code的按钮,单击其下的砸下来TPopupMenu。

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

示例:删除了TClickEvent(也许一个TButton)和你的窗体上的任何TPopupMenu。添加一些菜单项。然后添加下面的OnClick事件处理程序:

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.

注意:如果你想有一个延时,然后提取的另一种方法,code,然后设置一个计时器的OnClick并打开OnMouseLeave在的计时器。然后,如果定时器触发可以调用提取出的方法。不知道你会怎么做一个键盘点击。我不知道,如果Firefox等支持,要么。

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.

这篇关于如何创建下拉菜单按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆