简体   繁体   中英

Why does a simple ApplicationSetting PropertyBinding for a Form does not work in C#?

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...

Are you saving the settings after the form has been resized? Doesn't Windows already remember the last position and size of your form?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM