Click here to Skip to main content
13,044,428 members (114,921 online)
Click here to Skip to main content

Stats

114K views
3.1K downloads
62 bookmarked
Posted 7 Jan 2010

Save and Restore WPF Window Size, Position, and/or State

, 3 Aug 2012
A quick example of how you can save the window size, position, and/or state, and restore your form to that size, position, and state the next time the app is launched.
<?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="SaveWindowPosition.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <SaveWindowPosition.Properties.Settings>
            <setting name="WindowTop" serializeAs="String">
                <value>100</value>
            </setting>
            <setting name="WindowLeft" serializeAs="String">
                <value>100</value>
            </setting>
            <setting name="WindowHeight" serializeAs="String">
                <value>300</value>
            </setting>
            <setting name="WindowWidth" serializeAs="String">
                <value>300</value>
            </setting>
            <setting name="WindowState" serializeAs="String">
                <value>Normal</value>
            </setting>
        </SaveWindowPosition.Properties.Settings>
    </userSettings>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jeremy Hutchinson
Software Developer
United States United States
I develop applications using Angular, ASP.Net MVC and SQL hosted on AWS by day, and in my free time I develop apps for Windows Phone and Windows 10 as well as web apps hosted in Azure. I always try to blog about what I've learned.

I also help run the Casco Bay .Net User Group

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 3 Aug 2012
Article Copyright 2010 by Jeremy Hutchinson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid