/// <summary> /// Handle Load event. Loads position settings and moves/sizes the /// form. /// </summary> private void OnLoad(object sender, System.EventArgs e) { dimensions.X = form.Left; dimensions.Y = form.Top; dimensions.Width = form.Width; dimensions.Height = form.Height; FormWindowState windowState = form.WindowState; // Attempt to read state from preferences. Preferences prefReader = Preferences.GetUserNode(GetType()); prefReader = prefReader.GetSubnode(FormName); Point location = new Point( prefReader.GetInt32("Left", form.Left), prefReader.GetInt32("Top", form.Top)); dimensions.Location = AdjustLocationToAvailableScreens(location); if (!this.saveOnlyLocation) { dimensions.Width = prefReader.GetInt32("Width", form.Width); dimensions.Height = prefReader.GetInt32("Height", form.Height); } if (!this.saveNoWindowState) { windowState = (FormWindowState)prefReader.GetInt32("WindowState", (int)form.WindowState); } // Fire LoadState event. if (LoadStateEvent != null) { LoadStateEvent(this, prefReader); } prefReader.Close(); // Alter window state. form.Bounds = dimensions; form.WindowState = windowState; }
/// <summary> /// Handle Close event. Saves window state. /// </summary> private void OnClosing(object sender, CancelEventArgs e) { // If the window state is minimized, save as normal. if (windowState == FormWindowState.Minimized) { windowState = FormWindowState.Normal; } // Save position, size and state to preferences. Preferences prefWriter = Preferences.GetUserNode(GetType()); prefWriter = prefWriter.GetSubnode(FormName); prefWriter.SetProperty("Left", dimensions.Left); prefWriter.SetProperty("Top", dimensions.Top); if (this.saveOnlyLocation) { prefWriter.SetProperty("Width", null); // removes the entry prefWriter.SetProperty("Height", null); } else { prefWriter.SetProperty("Width", dimensions.Width); prefWriter.SetProperty("Height", dimensions.Height); } if (this.saveNoWindowState) { prefWriter.SetProperty("WindowState", null); } else { prefWriter.SetProperty("WindowState", (int)windowState); } // Fire SaveState event. if (SaveStateEvent != null) { SaveStateEvent(this, prefWriter); } prefWriter.Close(); }
private void CmPreferences_OnClick(object sender, RoutedEventArgs e) { if (_showingPreferences) { return; } var preferences = new Preferences(); preferences.DataContext = new PreferencesViewModel(_config, () => preferences.Close()); preferences.WindowStartupLocation = WindowStartupLocation.CenterScreen; _showingPreferences = true; preferences.Show(); preferences.Closed += (s, ev) => { _showingPreferences = false; }; }