c# - ContextMenuStrip DefaultDropDownDirection 不起作用

标签 c# winforms

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

enter image description here

我的 ContextMenuStrip 总是从左侧打开。我尝试设置 DefaultDropDownDirection,但徒劳 -> 无论我选择什么 ToolStripDownDirection,它总是相同的:

 _menuStrip.DefaultDropDownDirection = ToolStripDropDownDirection.BelowRight;

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

最佳答案

您应该使用 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);
}

关于c# - ContextMenuStrip DefaultDropDownDirection 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20311927/

相关文章:

c# - 在 C# 中聚合接口(interface)

c# - 将硬编码数据传输到数组

c# - 是否足以禁止输入中的单引号以避免 SQL 注入(inject)?

c# - 如何将值传递给用户控件?

c# - 使用分页时不显示用户详细信息

c# - 如何为 C# Windows 窗体定义窗口类名?

c# - 在c#中使用鼠标绘制矩形

c# - 如何在 C# TBB(C# 代码片段)中添加用户定义的方法?

c# - 如何在 C# 中重定向**现有**进程的 STD-Out

c# - IValueCONverter 不工作