ContextMenuStrip display issue

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have been trying to solve this for a while.  I have only seen one post online mentioning it and the problem was never resolved, so Ill ask here:
 
How do you keep a ContextMenuStrip on the correct screen?  I have an application that utilizes a large number of screens (as many as 32 so far), and I run a pair on both my desktop computers, so this problem crops up every time I try to utilize the ContextMenuStrip rather than the old windows API context menu.  Youll need a multiple monitor setup to see this problem...
  <font size=2>
</font><font color="#0000ff" size=2>
<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet <font color="#0000ff" size=2><font size=2>
</font><font color="#0000ff" size=2>Private</font><font size=2> </font><font color="#0000ff" size=2>Sub</font><font size=2> Form1_Load(</font><font color="#0000ff" size=2>ByVal</font><font size=2> sender </font><font color="#0000ff" size=2>As</font><font size=2> </font><font color="#0000ff" size=2>Object</font><font size=2>, </font><font color="#0000ff" size=2>ByVal</font><font size=2> e </font><font color="#0000ff" size=2>As</font><font size=2> System.EventArgs) </font><font color="#0000ff" size=2>Handles</font><font size=2> </font><font color="#0000ff" size=2>Me</font><font size=2>.Load
</font><font color="#008000" size=2>  Declare ContextMenuStrip and ToolStripMenuItem (for dropdown). </font><font size=2>
</font><font color="#0000ff" size=2>  Dim</font><font size=2> MyContextMenuStrip </font><font color="#0000ff" size=2>As</font><font size=2> </font><font color="#0000ff" size=2>New</font><font size=2> ContextMenuStrip
</font><font color="#0000ff" size=2>  Dim</font><font size=2> MyContextMenuDropdown </font><font color="#0000ff" size=2>As</font><font size=2> </font><font color="#0000ff" size=2>New</font><font size=2> ToolStripMenuItem</font>
<font size=2> 
</font><font color="#008000" size=2>  Create menu </font><font size=2>
  MyContextMenuStrip.Items.Add(</font><font color="#a31515" size=2>"Test Item"</font><font size=2>)
  MyContextMenuDropdown.Text = </font><font color="#a31515" size=2>"Another Item" </font><font size=2>
  MyContextMenuDropdown.DropDownItems.Add(</font><font color="#a31515" size=2>"Yet Another Item"</font><font size=2>)
  MyContextMenuStrip.Items.Add(MyContextMenuDropdown)
 
</font><font color="#008000" size=2>  Assign to the property for the form. </font><font size=2>
</font><font color="#0000ff" size=2>  Me</font><font size=2>.ContextMenuStrip = MyContextMenuStrip
</font><font color="#0000ff" size=2>End</font><font size=2> </font><font color="#0000ff" size=2>Sub </font></font>
  </font>
Just toss the above code into a form and run it.  Now, move the form to the far right of a screen with another screen to the right of it and right click near the right edge.  I expect it to stay on the same screen, but it jumps to the next screen.  Further, if you right-click far enough to the left in that form that the menu stays on the left-hand screen and hover the submenu menu, it will end up on the right-hand screen.
 
Ive tried everything I could find in the ContextMenuStrip class, but nothing seems to restrict it to the boundaries of the screen where the click was made, which is how the old context menus worked.  Just close the window and right-click on the desktop near the edges and youll see how it should work, including the submenus.
 
Any help would be greatly appreciated.
 
Thanks.
<font color="#0000ff" size=2> </font>

View the full article
 
Back
Top