public SettingsWindow(SettingsData data) { InitializeComponent(); //Load the incoming (existing) settings from the main form LoadSettingsData(data); }
/// <summary> /// Setup and configure this form's controls using the provided settings /// </summary> /// <param name="data">Settings to use when setting up this form</param> public void LoadSettingsData(SettingsData data) { //Keep the existing settings so that rollbacks can be performed via the Revert Buttons. _initialData = data; //Setup the Format tab SetDateTimeFormat(data.DateTimeFormat); //Setup the Colors tab SetColors(data.Foreground, data.Background); //Setup the Font tab SetListBoxFont(data.Font); //Put focus on the appropriate tab via index tcSettings.SelectedIndex = data.TabIndex; }
/// <summary> /// Menu item (Menu Bar at the top of the form) click handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItemSettings_Click(object sender, RoutedEventArgs e) { //Collect all of the Form's Current settings in preparation for the Settings Form SettingsData data = new SettingsData(); data.DateTimeFormat = _source.GetCurrentFormat(); //Get the current Date/Time formats data.Font = lblCurrentDate.FontFamily; //The font family for one of the labels (will be used for all of the labels) data.Foreground = lblCurrentDate.Foreground; //The foreground for one of the labels (will be used for all of the labels) data.Background = this.Background; //This form's background color data.TabIndex = GetSettingsTabIndex(((MenuItem)sender)); //Get the destination tab index //Create new settings window instance SettingsWindow win = new SettingsWindow(data); //Register the settings window applied event win.Applied += new SettingsWindow.FormatApplied(SettingsWindow_OnApplied); //This line both opens the dialog and when the window is closed will unregister the applied event if(win.ShowDialog() == true) win.Applied -= new SettingsWindow.FormatApplied(SettingsWindow_OnApplied); }
/// <summary> /// Apply the user supplied Date and Time formats to the Main Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFormatApply_Click(object sender, RoutedEventArgs e) { SettingsData data = new SettingsData(); data.DateTimeFormat = GetEnteredFormat(); Applied(sender, new SettingsDataArgs() { NewSettings = data }); }
/// <summary> /// Apply the user supplied Color Choices to the Main Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnColorApply_Click(object sender, RoutedEventArgs e) { SettingsData data = new SettingsData(); data.Background = new SolidColorBrush(cpBackgroundColor.SelectedColor); data.Foreground = new SolidColorBrush(cpForegroundColor.SelectedColor); Applied(sender, new SettingsDataArgs() { NewSettings = data }); }
/// <summary> /// Apply the user supplied Font choice to the Main Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ApplyFontSettings(object sender) { SettingsData data = new SettingsData(); data.Font = (FontFamily)lbFonts.SelectedItem; Applied(sender, new SettingsDataArgs() { NewSettings = data }); }