I am trying to save the position of a custom dialog to the users registry, so that when they reload the same dialog, it appears in the same place they moved or resized it to pre
You want something like this when you save the window position:
if (this.WindowState == WindowState.Normal)
{
Properties.Settings.Default.Top = Top;
Properties.Settings.Default.Left = Left;
Properties.Settings.Default.Height = Height;
Properties.Settings.Default.Width = Width;
}
else
{
Properties.Settings.Default.Top = RestoreBounds.Top;
Properties.Settings.Default.Left = RestoreBounds.Left;
Properties.Settings.Default.Height = RestoreBounds.Height;
Properties.Settings.Default.Width = RestoreBounds.Width;
// Check for WindowState.Maximized or WindowState.Minimized if you
// need to do something different for each case (e.g. store if application
// was Maximized
}
The important bit is the RestoreBounds which you need when the window is maximised or minimised. The code can probably be refactored to make it more efficient, but you get the idea.