leo*_*ora 13 c# button contextmenustrip winforms
我想点击一个按钮,让它在按钮下方显示一个上下文.当我尝试使用pointtoacreen和top和left坐标时,它会一直显示在屏幕的左侧.
有什么建议
A J*_*shi 39
我知道这是一个老问题,但我认为这可能有助于其他人.以下代码将显示正在单击按钮下方的上下文菜单,该按钮看起来像一个下拉按钮.
private void Button1_Click(object sender, EventArgs e)
{
Button btnSender = (Button)sender;
Point ptLowerLeft = new Point(0, btnSender.Height);
ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
ctMenuStrip.Show(ptLowerLeft);
}
Run Code Online (Sandbox Code Playgroud)
leo*_*ora 23
我想到了:
layoutMenus.Show(Cursor.Position.X, Cursor.Position.Y);
Run Code Online (Sandbox Code Playgroud)
小智 5
在按钮下方的ContexMenuName,与按钮的右侧对齐(向下扩展到按钮和向左):
ContexMenuName.Show(ButtonName, new Point(ButtonName.Width - ContexMenuName.Width, ButtonName.Height));
希望这将有助于某人:)
| 归档时间: |
|
| 查看次数: |
42482 次 |
| 最近记录: |