用下拉菜单按钮Windows.Forms的 [英] Windows.Forms button with drop-down menu
问题描述
我正在开发使用.NET的Windows.Forms的简单的C#应用程序。我需要一些按钮,将显示与子下拉菜单 - 很像ToolStripMenu,但按钮,你知道的。我搜索了它,可能没有发现任何变种。
I'm developing simple C# application using Windows.Forms on .NET. I need some button that will show a drop-down menu with subcategories - much like ToolStripMenu, but the button, you know. I searched for it and could not found any variants.
我的问题是:有没有办法做到这一点,也许一些秘密按钮属性,允许附加菜单它
My question is: is there any way to do this, maybe some secret button property that allows attach menu to it?
任何帮助将不胜感激。
推荐答案
您可以显示的ContextMenuStrip上的click事件:
You can show the ContextMenuStrip on the click event:
private void button1_Click(object sender, EventArgs e) {
contextMenuStrip1.Show(button1, new Point(0, button1.Height));
}
为使自己的决定是否显示上方或下方的按钮菜单,您可以尝试使用此代码,它测量菜单,并确定它是否会被部分离屏:
To make your own determination whether to show the menu above or below the button, you can try using this code, which measures the menu and determines whether or not it would be partially offscreen:
private void button1_Click(object sender, EventArgs e) {
Point screenPoint = button1.PointToScreen(new Point(button1.Left, button1.Bottom));
if (screenPoint.Y + contextMenuStrip1.Size.Height > Screen.PrimaryScreen.WorkingArea.Height) {
contextMenuStrip1.Show(button1, new Point(0, -contextMenuStrip1.Size.Height));
} else {
contextMenuStrip1.Show(button1, new Point(0, button1.Height));
}
}
这篇关于用下拉菜单按钮Windows.Forms的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!