为什么表单的简单 ApplicationSetting PropertyBinding 在 C# 中不起作用?
我的问题涉及文章 保留 Windows 窗体的大小和位置 - 第 I 部分 作者:Dennis Wallentin。
使用 VB.NET 时,此方法可以 100% 正常工作。但是,在 C# 中使用相同的步骤时,应用程序属性的“设置”选项卡中的设置看起来正确,并且 app.config 文件看起来正确,但运行该文件时不会保存这些值。
app.config 文件最终看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WindowsAppCs.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<WindowsAppCs.Properties.Settings>
<setting name="Location" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="Size" serializeAs="String">
<value>284, 262</value>
</setting>
</WindowsAppCs.Properties.Settings>
</userSettings>
</configuration>
它对我来说看起来不错,但在 Visual Studio 中托管运行或运行已编译的 EXE 时,这些值不会更新。
我确信需要添加或完成一些非常简单的事情,但我不知道是什么。这里有人有什么想法吗?
预先非常感谢...
My question involves this simple walkthrough shown in the article Preserve Size and Location of Windows Forms – Part I by Dennis Wallentin.
This approach works 100% fine when using VB.NET. When using the same steps in C#, however, the settings within the Settings tab of the application's properties looks correct, and the app.config file looks right, but the values are not saved when you run it.
The app.config file winds up looking like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WindowsAppCs.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<WindowsAppCs.Properties.Settings>
<setting name="Location" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="Size" serializeAs="String">
<value>284, 262</value>
</setting>
</WindowsAppCs.Properties.Settings>
</userSettings>
</configuration>
It looks right to me, but the values do not update when running hosted within Visual Studio or when running the compiled EXE.
I am sure that something very simple needs to be added or done, but I don't know what. Does anyone have any ideas here?
Much thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调整表单大小后是否保存设置? Windows 不是已经记住了窗体的最后位置和大小吗?
Are you saving the settings after the form has been resized? Doesn't Windows already remember the last position and size of your form?