ContextMenuStrip DefaultDropDownDirection不起作用

时间:2013-12-01 12:08:16

标签: c# winforms

我为NotifyIcon创建了ContextMenuStrip(在系统托盘中)。但是,ContextMenuStrip的方向总是在左边。我注意到在许多其他应用程序(如Skype)上,它正在右侧打开:

enter image description here

Mine ContextMenuStrip总是在左侧打开。我试图设置DefaultDropDownDirection,但徒劳无功 - >无论我选择哪种ToolStripDownDirection,它总是一样的:

 _menuStrip.DefaultDropDownDirection = ToolStripDropDownDirection.BelowRight;

我希望能够改变ContextMenuStrip打开的方向。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您应该使用Opening事件(msdn)和ContextMenuStrip.Show方法(msdn):

...
ContextMenuStrip _menuStrip = new ContextMenuStrip();        
_menuStrip.Opening +=_menuStrip_Opening;
...

打开事件处理程序:

void _menuStrip_Opening(object sender, CancelEventArgs e)
{   
    ContextMenuStrip menuStrip = (sender as ContextMenuStrip);
    menuStrip.Show(Cursor.Position, ToolStripDropDownDirection.AboveRight);
}