.NET WPF Remember window size between sessions

后端 未结 12 932
悲哀的现实
悲哀的现实 2020-11-30 20:33

Basically when user resizes my application\'s window I want application to be same size when application is re-opened again.

At first I though of handling SizeChange

12条回答
  •  我在风中等你
    2020-11-30 20:44

    While you can "roll your own" and manually save the settings somewhere, and in general it will work, it is very easy to not handle all of the cases correctly. It is much better to let the OS do the work for you, by calling GetWindowPlacement() at exit and SetWindowPlacement() at startup. It handles all of the crazy edge cases that can occur (multiple monitors, save the normal size of the window if it is closed while maximized, etc.) so that you don't have to.

    This MSDN Sample shows how to use these with a WPF app. The sample isn't perfect (the window will start in the upper left corner as small as possible on first run, and there is some odd behavior with the Settings designer saving a value of type WINDOWPLACEMENT), but it should at least get you started.

提交回复
热议问题