I am struggling with persisting the items in MenuStrip and ToolStrips. I have one MenuStrip and two ToolStrips, similar to Word 2003. I have themin ToolStripPanels. I have four ToolStripPanels, one on each side of the form so that the menu/toolstrips can be drag around. When my form is loaded, I run this:
ToolStripManager.SaveSettings(this); //for reset ToolStripManager.LoadSettings(this, "Custom"); //custom
When my form exits, I run this:
ToolStripManager.SaveSettings(this, "Custom");
I have a reset function for the user, whence I run this:
ToolStripManager.LoadSettings(this);
Let's focus on the MenuStrip, which has the following items in this order at design time: File, Edit, Format, Tools, Window, Help.
I notice that the settings are stored in Application.LocalUserAppDataPath + @"\myapp.exe_StrongName_umcsk.....\assembly version\user.config", where _umcsk... is some cryptic string and assemby version is the four-part version number, eg 2.0.3545.38747.
In user.config, the reset information for MenuStrip is in <System.Windows.Forms.ToolStripSettings.mynamespace.Form1.menuStrip1> and it appears that the <setting name='ItemOrder'> is always correct: <value>menuFile,menuEdit,menuFormat,menuTools,menuWindow,menuHelp</value>
When I move a menu item (by Alt-mouse drag), eg I move the Help menu to the left of Window, and then exit, user.config now contains a <System.Windows.Forms.ToolStripSettings.Custom.menuStrip1> with an ItemOrder element with <value>,,,menuFormat,menuTools,menuWindow,menuHelp,menuFile,menuEdit</value>. I suspect the extra commas are causing the problem. When I run the application again, now the order of the menu items are jumbled up in some unexplained sequence.
If I manually remove the extra commas and run the application, the menu item orderis now correct. How can I prevent/remove the extra commas?
Thanks. | | K.Kong Tuesday, September 15, 2009 2:20 PM | I find that the four-comma problem in user.config is consistently generated if I maximize a child form. Apparently this action alone will cause the problem, and the absence of this action will also not generate four commas. I worked around the problem by String.Replace("<value>,,,,","<value>") in user.config. user.config is located in
ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath. - Marked As Answer byAland LiMSFT, ModeratorThursday, October 01, 2009 4:18 AM
-
| | K.Kong Thursday, October 01, 2009 3:52 AM | Forgot to mention that other than shown above, I have no self-written code on the MenuStrip or ToolStripPanels. It's from VS designer to the exe. | | K.Kong Tuesday, September 15, 2009 3:33 PM | Hi K.Kong, Could you please create a small project in which the issue can be reproduced and email to me: alala666888@hotmail.com? I have tested a similar projectbut did not meet the same issue. Regards, Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 17, 2009 8:23 AM | Aland, thanks for your offer. I have been trying to create a test project for some time, but I can't find the ToolStripPanel control on the Toolbox. Can someone give me pointers to getting theToolStripPanel control backin the Toolbox. I defintely did not create the ToolStripPanel manually in code.
By the way, I took the exe and ran it on a Windows Server 2003. Same problem. The moment any MenuStrip or ToolStrip is adjusted, four commas are added to the ItemOrder element. | | K.Kong Thursday, September 17, 2009 8:35 AM | Hi K.Kong,
You can right click the toolbox and select Reset Toolbox.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 17, 2009 8:37 AM | By the way, I took the exe and ran it on a Windows Server 2003. Same problem. The moment any MenuStrip or ToolStrip is adjusted, four commas are added to the ItemOrder element.
Hi K.Kong, Do you mean adjusting their orders programmatically in runtime? Regards, Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 17, 2009 8:40 AM | Aland, no. I didn't write any code. I used everything that is built-in, with just setting the properties of the various controls in Designer. At runtime, the user can drag to move the MenuStrip or ToolStrip, and the items within these strips can be moved by Alt-Drag. I reset the Toolbox and it two minutes of disk churning. Still no ToolStripPanel. Do you see one in your Toolbox?  | | K.Kong Thursday, September 17, 2009 8:58 AM | Hi K.Kong,
Sorry for not clearly understanding what you want. There is no ToolStripPanel control, we can only use ToolStrip and ToolStripContainer.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 17, 2009 9:01 AM | Hi K.Kong,
Sorry for not clearly understanding what you want. There is no ToolStripPanel control, we can only use ToolStrip and ToolStripContainer.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 17, 2009 9:02 AM | Aland I managed to find back the ToolStripPanel control. In Tools, Choose Toolbox Items...
Anyway, before I discovered that, I copied my huge project and hand-modified to remove all the unnecessary clutter to product a Test ToolStripPanel project which I have mailed to you.
Thanks. | | K.Kong Thursday, September 17, 2009 10:55 AM | Hi K.Kong,
Sorry for the late reply. I have received the email, but the attachment is prevented, please package the file and send to me again. The ToolStripPanelcannot be found in theToolBox but can be added as follows: 1. Right click ToolBox andclick Choose Items. 2. In .Net Framework Components tab, find andcheck ToolStripPanel, click OK.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Friday, September 18, 2009 4:07 AM | Hi K.Kong,
I have tested the project you sent to me with the same steps. But the form shows fine and the itemorder in user.config is also correct.
Could you please tell me the version of the operation system and visual studio on your machine, so that I can test in the same environment?
Regards, Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Monday, September 21, 2009 4:00 AM | Aland, Mine is VS 2008 9.0.30729.1 SP on Vista Business SP 2 with .NET Framework 3.5 SP1. I took the sameexe and run on a Server 2003, Windows 2000 SP4,Windows XP SP3,and the error outcome was consistently the same. The steps to reproduce are: a. Launch "Test ToolStripPanel.exe". b. Click Window New Window to open a child Form2. c. Maximize the child Form2. d. Alt-drag Help to the left of Window. e. Exit program. f. Run program again. The order of items in the menu strip will be jumbled up. Check user.config. There will be four commas added to ItemOrder in Custom.menuStrip1. After spending more time testing, I notice that the four commas problem will occur if child Form2 is maximized. And I don't even have to move items on the menu strip to see the problem. If the child Form2 is not created or maximized then the four commas problem may not be there. user.configislocatedin a variation of Application.LocalUserAppDataPath. In Vista, it could be inC:\Users\<userid>\AppData\Local\Test_Inc\Test_ToolStripPanel.exe_StrongName_1wvpv0l1p0h1wkfdll5xmpo1lbwweacg\2.0.0.0. I have uploaded a copy of the exe to http://sameoldplace.net/pimages/Test ToolStripPanel.exe. It is safe to run. Thanks. | | K.Kong Monday, September 21, 2009 6:15 AM | I find that the four-comma problem in user.config is consistently generated if I maximize a child form. Apparently this action alone will cause the problem, and the absence of this action will also not generate four commas. I worked around the problem by String.Replace("<value>,,,,","<value>") in user.config. user.config is located in
ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath. - Marked As Answer byAland LiMSFT, ModeratorThursday, October 01, 2009 4:18 AM
-
| | K.Kong Thursday, October 01, 2009 3:52 AM |
|