Saving the location of a dashboard user not yet working in VS2012

For many years I struggled with several tools in the toolstripcontainer. I have a current .NETv3.5 application written in VS2008 where the location of the dashboards is random. A lot of custom code has been made to fix this, but with no luck.

I am currently working in VS2012 on a .NETv4.5 application that also has several tools. I created a very small test application, which is a form with an attached toolstripcontainer and 4 dashboards. During development, I added 3 toolbars at the bottom and 1 to the right.

Without adding code and starting this application, my dashboards are located in the same place as during development. Now I reorder the top 3 toolbars and restart the application. My order changes are not saved, and the dashboards again, as during development.

Now I am adding these lines of code:

public partial class Toolstrips : Form { private string keyName; public Toolstrips() { this.InitializeComponent(); this.keyName = Application.ProductName + this.Name + "xyz"; ToolStripManager.LoadSettings(this, this.keyName); } private void Toolstrips_FormClosing(object sender, FormClosingEventArgs e) { ToolStripManager.SaveSettings(this, this.keyName); } } 

And yet in VS2102 with .NETv4.5 this does not work. I can change the order that I want after restarting the application, and all toolbars will be restored to temporary project locations.

I was hoping this would be fixed in VS2012, but apparently not. Does anyone have a job to make this work?

EDIT: added user.config content

 <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripTable" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> <section name="System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripPan" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> <section name="System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripStandard" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> <section name="System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripZoom" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> </sectionGroup> </configSections> <userSettings> <System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripTable> <setting name="ItemOrder" serializeAs="String"> <value>toolStripButton4</value> </setting> <setting name="IsDefault" serializeAs="String"> <value>False</value> </setting> <setting name="Size" serializeAs="String"> <value>29, 42</value> </setting> <setting name="ToolStripPanelName" serializeAs="String"> <value>toolStripContainer1.Right</value> </setting> <setting name="Visible" serializeAs="String"> <value>True</value> </setting> <setting name="Location" serializeAs="String"> <value>0, 336</value> </setting> <setting name="Name" serializeAs="String"> <value>toolStripTable</value> </setting> </System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripTable> <System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripPan> <setting name="ItemOrder" serializeAs="String"> <value>toolStripButton3</value> </setting> <setting name="IsDefault" serializeAs="String"> <value>False</value> </setting> <setting name="Size" serializeAs="String"> <value>40, 31</value> </setting> <setting name="ToolStripPanelName" serializeAs="String"> <value>toolStripContainer2.Top</value> </setting> <setting name="Visible" serializeAs="String"> <value>False</value> </setting> <setting name="Location" serializeAs="String"> <value>288, 0</value> </setting> <setting name="Name" serializeAs="String"> <value>toolStripPan</value> </setting> </System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripPan> <System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripStandard> <setting name="ItemOrder" serializeAs="String"> <value>newToolStripButton,openToolStripButton,saveToolStripButton,printToolStripButton,toolStripSeparator,cutToolStripButton,copyToolStripButton,pasteToolStripButton,toolStripSeparator1,helpToolStripButton</value> </setting> <setting name="IsDefault" serializeAs="String"> <value>False</value> </setting> <setting name="Size" serializeAs="String"> <value>248, 31</value> </setting> <setting name="ToolStripPanelName" serializeAs="String"> <value>toolStripContainer2.Top</value> </setting> <setting name="Visible" serializeAs="String"> <value>False</value> </setting> <setting name="Location" serializeAs="String"> <value>6, 0</value> </setting> <setting name="Name" serializeAs="String"> <value>toolStripStandard</value> </setting> </System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripStandard> <System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripZoom> <setting name="ItemOrder" serializeAs="String"> <value>toolStripButton1,toolStripButton2</value> </setting> <setting name="IsDefault" serializeAs="String"> <value>False</value> </setting> <setting name="Size" serializeAs="String"> <value>29, 73</value> </setting> <setting name="ToolStripPanelName" serializeAs="String"> <value>toolStripContainer2.Right</value> </setting> <setting name="Visible" serializeAs="String"> <value>False</value> </setting> <setting name="Location" serializeAs="String"> <value>0, 71</value> </setting> <setting name="Name" serializeAs="String"> <value>toolStripZoom</value> </setting> </System.Windows.Forms.ToolStripSettings.GUI-prototypeToolstripsxyz.toolStripZoom> </userSettings> </configuration> 

EDIT2 I created a small VS2012 application written in C # to illustrate my problem. You can download it here: https://mapwindow5.svn.codeplex.com/svn/tmp/ToolstripDemo/ToolstripDemo.zip When I launch the application, I see:

Initial load

When I reorder the 3 top dashboards, I get the following:

After reorder

Now I close the application and open it again, I get the starting locations:

After reopen

Now I move the toolbar that was attached to the top right:

Reorder again

I open the application again, and I see that the 4th toolbar is still at the top, which is normal, but there is no order. Look at the last two toolbars:

Reopen again

Another weird thing is that I cannot reorient the zoom bar to the right again. The dashboard just disappears:

enter image description here

When I open the form in VS2012, the dashboards also rearrange: Design time

I'm not sure why. I just open the form.

I did my testing and took screenshots by running exe from Explorer, and not in VS debugging mode.

Hopefully now it’s clearer what I mean and what I need. Any advice is greatly appreciated.

+4
source share
1 answer

I am using vb.net 2010, so I am using vb syntax, but I hope my answer helps:

1) Using the ToolStripManager, you can save and load settings without specifying a key for all toolbars separately. Setting the form is enough - the settings will be saved for the form using the form name as the key.

2) It is important to call ToolStripManager.SaveSettings () and ToolStripManager.LoadSettings (), which were not added in some other programmatic way, changing the layout of toolbars at runtime in the FormLoad and FormClosing startup procedures. Thus, the safest way to do this is to simply call the methods as the first in the FormClosing and FormLoad lookups, as shown below:

 Private Sub Explorer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ToolStripManager.LoadSettings(Me)'Me is the form, for which we save the toolbars settings 'further code in this subroutine End Sub Private Sub Explorer1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing ToolStripManager.SaveSettings(Me) My.Settings.Save() 'further code in this subroutine End Sub 
+1
source

Source: https://habr.com/ru/post/1502778/


All Articles