[英]Save user location of toolstrip still not working in VS2012
I've been struggling with multiple toolstrips in a toolstripcontainer for years. 多年来,我一直在使用工具条容器中的多个工具条。 I have a current .NETv3.5 application written in VS2008 where the location of the toolstrips are random.
我有一个用VS2008编写的当前.NETv3.5应用程序,其中工具条的位置是随机的。 A lot of custom code have been made to fix this but without any luck.
已经制作了许多自定义代码来解决这个问题,但没有任何运气。
Currently I'm working in VS2012 on a .NETv4.5 application which also has multiple toolstrips. 目前我在VS2012上使用.NETv4.5应用程序,该应用程序也有多个工具条。 I created a very small test application that is a form with a docked toolstripcontainer and 4 toolstrips.
我创建了一个非常小的测试应用程序,它是一个带有docked tooltripcontainer和4个工具条的表单。 At design time I added 3 toolstrips to the bottom and 1 to the right.
在设计时我在底部添加了3个工具条,在右边添加了1个工具条。
Without adding any code and starting this application, my toolstrips are located at the same location as in design time. 在不添加任何代码并启动此应用程序的情况下,我的工具条位于与设计时相同的位置。 Now I reorder the 3 top toolstrips and restart the application.
现在我重新排序3个顶级工具条并重新启动应用程序。 My reorder changes are not saved the toolstrips are again as in design time.
我的重新排序更改未保存,工具条再次与设计时间一样。
Now I add 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 still in VS2102 with .NETv4.5 this is not working. 而且在使用.NETv4.5的VS2102中,这不起作用。 I can reorder what I want after restarting the application all toolstrips are restored to the design time locations.
我可以在重新启动应用程序后重新排序我想要的所有工具条都恢复到设计时间位置。
I had hoped this would be fixed in VS2012 but apparently not. 我原本希望这可以在VS2012修复,但显然不是。 Does anybody have a work around to get this to work?
有没有人有办法让这个工作?
EDIT: Added contents user.config 编辑:添加内容user.config
<?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've created a small VS2012 application written in C# to illustrate my problem. EDIT2我创建了一个用C#编写的小型VS2012应用程序来说明我的问题。 You can download it here: https://mapwindow5.svn.codeplex.com/svn/tmp/ToolstripDemo/ToolstripDemo.zip When I start the application I see:
你可以在这里下载: https : //mapwindow5.svn.codeplex.com/svn/tmp/ToolstripDemo/ToolstripDemo.zip当我启动应用程序时,我看到:
When I reorder the 3 top toolstrips I get this: 当我重新排序3个顶级工具条时,我得到了这个:
Now I close the application and reopen it again, I get the initial locations: 现在我关闭应用程序并再次重新打开它,我得到了初始位置:
Now I move the toolstrip which was docked at the right to the top: 现在我将停靠在右侧的工具条移动到顶部:
I reopen the application and I see the 4th toolstrip is still at the top, which is OK but the order is not. 我重新打开应用程序,我看到第4个工具条仍然在顶部,这是可以的,但顺序不是。 Look at the two last toolstrips:
看看最后两个工具条:
Another strange thing is that I cannot redock my zoom-toolstrip to the right again. 另一个奇怪的事情是我无法再次向右移动我的zoom-toolstrip。 The toolstrip just disappears:
工具条刚刚消失:
When I open my form in VS2012 the toolstrips are rearranged as well: 当我在VS2012中打开表单时,工具条也会重新排列:
I'm not sure why. 我不知道为什么。 I'm just reopening the form.
我只是重新打开表格。
I did my testing and made the screenshots by running the exe from the explorer, not in debug-mode of VS. 我做了我的测试并通过运行来自资源管理器的exe来制作屏幕截图,而不是在VS的调试模式下。
I hope it is now more clear what I mean and what I need. 我希望现在更清楚我的意思和我需要什么。 Any advice is very much appreciated.
非常感谢任何建议。
I use vb.net 2010, so I use vb's syntax, but i hope my answer helps: 我使用vb.net 2010,所以我使用vb的语法,但我希望我的回答有所帮助:
1) Using ToolStripManager, You can save and load settings without specifying a key for all of toolbars seperately. 1)使用ToolStripManager,您可以保存和加载设置,而无需单独指定所有工具栏的键。 Specifying a form is enough - settings will be saved for a form using form's name as a key.
指定表单就足够了 - 将使用表单的名称作为键保存表单的设置。
2) It is important to call ToolStripManager.SaveSettings() and ToolStripManager.LoadSettings() not prepended by something else programaticaly changing toolbars layout at runtime in FormLoad and FormClosing event-run subroutines. 2)重要的是调用ToolStripManager.SaveSettings()和ToolStripManager.LoadSettings(),而不是在FormLoad和FormClosing事件运行子例程中运行时更改工具栏布局的其他内容。 So most safe way to do this, is just call the methods as first in FormClosing and FormLoad subs, as below:
因此,最安全的方法是在FormClosing和FormLoad subs中首先调用方法,如下所示:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.