为什么表单的简单 ApplicationSetting PropertyBinding 在 C# 中不起作用?

发布于 2024-08-26 08:14:23 字数 1553 浏览 5 评论 0原文

我的问题涉及文章 保留 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青朷 2024-09-02 08:14:23

调整表单大小后是否保存设置? 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文