Answered by:
Menu drop down appears at top left of screen

Question
-
Vs2010 WinForms
If when someone clicked a MenuStript Items MenuItem (like file, windows or help) you wanted the resulting dropdown to appear at the top-left of the screen instead of where it normally would appear, how would you program that?
It is not an academic question. I build my menu at run time and that is how it behaves. I've been looking for a couple of days and can't find anyting wrong.
If you answered the question it might just give me a clue.
Thanks
Answers
-
Sorry, I have no idea what would cause this. I was just trying to guess at a way something odd would happen. Normally I would just do something as follows:public Form1()
{
InitializeComponent();ToolStripMenuItem tsmi = new System.Windows.Forms.ToolStripMenuItem("Test");
ToolStripMenuItem tsmiFoo = new ToolStripMenuItem("Foo");
menuStrip1.Items.Add(tsmi);
tsmi.DropDownItems.Add(tsmiFoo);
}
--
Mike- Marked as answer by Michael Sun [MSFT]Microsoft employee Thursday, July 29, 2010 9:35 AM
-
I did not answer at once because the problem resoved itself as I continued to develop. I'm not sure what did it. Don't even have a guess. I tried to recreate it so I could send it but haven't been able to.
I had it for months before I submitted so it was firm for quite a while.
Thanks
PS Do you happen to know why when I reply there is no spell check. I really need one!
- Marked as answer by Michael Sun [MSFT]Microsoft employee Thursday, July 29, 2010 9:34 AM
All replies
-
Does your code look something like this? I suspect you may be missing the Point p = this.PointToScreen() call.public Form1()
{
InitializeComponent();
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = "Goofy";
tsmi.MouseDown += new MouseEventHandler(tsmi_MouseDown);
menuStrip1.Items.Add(tsmi);
}void tsmi_MouseDown(object sender, MouseEventArgs e)
{
ToolStripDropDown tsdd = new ToolStripDropDown();
tsdd.Items.Add("Pluto");
Point p = this.PointToScreen(e.Location);
tsdd.Show(p);
}
--
Mike -
In your example you add a ToolScriptMenuItem to the MenuStrip Items.
I do that. But I do not set MouseDown. Do yo handle MouseDown for every menu item? That would be a lot of code.
I create a MenuStrip with the Designer and in the Designer assign it to
MainMenuStrip. So the system shows it. Not me.
At run time I clear and then add menuitems to its ToolStripItemCollection as needed.
I also add menu items to the ToolStripItemCollection of the menu items added as mentioned above.
The one first above mentioned items added are the top level menu item that appear across the top of the window. These position OK and continue to work OK. But as I repeatly click them the drop downs at first appear under them as expected. But after repeatedly clicking they will suddenly no longer appear where they should but from then on instead appear at the screen's top left.
I think to cause the problem I must click one main level item and while it is displaying its drop down, move and click another item.
If you have any ideas at all as to what I might try I'd like very much to learn of them
Second question. With context menus I do do a Show as you describe, but on MouseUp. Should that be on MouseDown?
Thanks
-
Sorry, I have no idea what would cause this. I was just trying to guess at a way something odd would happen. Normally I would just do something as follows:public Form1()
{
InitializeComponent();ToolStripMenuItem tsmi = new System.Windows.Forms.ToolStripMenuItem("Test");
ToolStripMenuItem tsmiFoo = new ToolStripMenuItem("Foo");
menuStrip1.Items.Add(tsmi);
tsmi.DropDownItems.Add(tsmiFoo);
}
--
Mike- Marked as answer by Michael Sun [MSFT]Microsoft employee Thursday, July 29, 2010 9:35 AM
-
-
Hi calgeo,
Welcome to MSDN Forum!
This is a very strange issue if you have faced. We are also interesting in researching strange issue. So can you post your code on the forum?
And I also suggest you remove this post to the windows forms forum. There will be more people professional on this.
http://social.msdn.microsoft.com/Forums/en-us/winforms/threads
Best regards,
Mike
-
I did not answer at once because the problem resoved itself as I continued to develop. I'm not sure what did it. Don't even have a guess. I tried to recreate it so I could send it but haven't been able to.
I had it for months before I submitted so it was firm for quite a while.
Thanks
PS Do you happen to know why when I reply there is no spell check. I really need one!
- Marked as answer by Michael Sun [MSFT]Microsoft employee Thursday, July 29, 2010 9:34 AM
-
Vs2010 WinForms
If when someone clicked a MenuStript Items MenuItem (like file, windows or help) you wanted the resulting dropdown to appear at the top-left of the screen instead of where it normally would appear, how would you program that?
It is not an academic question. I build my menu at run time and that is how it behaves. I've been looking for a couple of days and can't find anyting wrong.
If you answered the question it might just give me a clue.
Thanks
I also encountered the same problem, but the item is one in menuitem when this is so, after adding a second, it is normal.why?
Private Sub ToolStripSplitButton1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripSplitButton1.Click
ToolStripSplitButton1.DropDownItems.Clear()
Dim objToolScriptMenuItem As ToolStripMenuItem = New ToolStripMenuItem
objToolScriptMenuItem.Text = "aa"
objToolScriptMenuItem.Name = "aa"
ToolStripSplitButton1.DropDownItems.Add(objToolScriptMenuItem)
End Sub- Edited by bennyfromc Thursday, December 5, 2013 2:54 AM
-
I had the same thing happening to me.
What caused it for me was that I dynamically populated the toolstripdropdown with the click event.
You have to populate it dynamically with the DropDownOpening event.
Making that change solved it for me.
- Edited by John of York Wednesday, February 6, 2019 12:22 AM
-
You know guys I am facing the same problem 13 year later. We have an application that is running from years already, and suddenly it starting this weird behavior 2 weeks ago.
We changed resolution settings, windows font sizing, anything and we don't know yet what it is happening.
As you may think, this application was not changed since months ago, but suddenly it started this weird behavior.
At this point we tried with Windows 11, Windows 10 and it is doesn't matter what build of Windows we use.
This application uses Telerik Wincontrols. so I don't know if there was a recent update on Windows that could screw this?