Beispiel #1
0
        private void FrmSettings_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.Cancel)
            {
                DialogResult dr = MessageBox.Show(@"Exit without saving?", @"Exit | Save",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (dr != DialogResult.Yes)
                {
                    e.Cancel = true;
                }
            }
            if (DialogResult == DialogResult.OK)
            {
                SettingsAdapter.Starttime(start.Text.ToTime());
                SettingsAdapter.PeriodTime(ptime.Text.ToInt());
                SettingsAdapter.Songstime(stime.Text.ToTime());
                SettingsAdapter.Playlist(_path);
                SettingsAdapter.Interval(inttime.Text.ToInt());
                SettingsAdapter.Lunch(lunch.Text.ToInt());
                SettingsAdapter.Theme(themelight.Checked);

                SettingsAdapter.Save();

                _materialSkinManager.Theme = SettingsAdapter.Theme() ?
                                             MaterialSkinManager.Themes.Light : MaterialSkinManager.Themes.Dark;
                //  try
                //  {
                RegistryKey k = Registry.CurrentUser.OpenSubKey(
                    @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                if (startup.Checked)
                {
                    try
                    {
                        if (k != null)
                        {
                            k.DeleteValue("Bell");
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                    if (k != null)
                    {
                        k.SetValue("Bell", Application.ExecutablePath.Replace(@"/", @"\"),
                                   RegistryValueKind.String);
                        k.Close();
                    }
                }
                else
                {
                    try
                    {
                        if (k != null)
                        {
                            k.DeleteValue("Bell");
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                    if (k != null)
                    {
                        k.Close();
                    }
                }
                // }
                //// catch { }
            }
        }