在Windows中创建菜单按钮 [英] Creating a menu button in Windows
问题描述
Microsoft的用户体验互动指南给出了一些UI指南何时使用菜单按钮:
Microsoft's User Experience Interaction Guidelines give some UI guidelines for when to use a menu button:
http://i.msdn.microsoft.com/Aa511453.command51(zh-CN,MSDN.10).png
http://i.msdn.microsoft.com/Aa511453.command51(en-us,MSDN.10).png
如何创建这些菜单按钮之一?我发现有关
How do I create one of these menu buttons? I've found information on
- 如何在Vista及以上版本中创建分割按钮的信息
- 如何创建带有下拉菜单的工具栏按钮
- 如何创建常规按钮,并手动连接弹出菜单的OnClick事件处理程序
但是,有没有什么标准的方式来创建一个按钮,而不是在工具栏中,使用小三角形,点击时会自动弹出一个菜单?
But is there any standard way to create a button, not in a toolbar, with the little down triangle, that automatically pops up a menu when clicked?
(我使用的是Delphi / C ++ Builder,但其他解决方案是可以接受的。)
(I'm using Delphi / C++Builder, but other solutions are welcome.)
推荐答案
p>您可以使用OnClick强制弹出窗口,一致性不要使用光标位置,而是使用控制位置。
You can use the OnClick to force the popup, and for consistency don't use the cursor position, but rather the control position.
procedure TForm1.Button1Click(Sender: TObject);
var
pt : TPoint;
begin
Pt.X := Button1.Left;
Pt.Y := Button1.Top+Button1.Height;
pt := ClientToScreen(Pt);
PopupMenu1.Popup(pt.x,pt.y);
end;
然后您可以使用Delphi 2010按钮或以前的版本TBitBtn添加glyph,将位图/ glyph属性分配给适当的图像并对齐。
You can then add the "glyph" using either a Delphi 2010 button, or a previous version TBitBtn and assign the bitmap/glyph property to an appropriate image and align right.
这篇关于在Windows中创建菜单按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!