private void Form1_FormClosing(object sender, FormClosingEventArgs e) { settings.Port = int.Parse(portTextBox.Text); if (String.IsNullOrWhiteSpace(pwTextBox.Text)) { settings.Pw = ""; } else { settings.Pw = KeyContainerManager.Encrypt(pwTextBox.Text, KeyContainerManager.CreateKeys("KeyReceiver")); } settings.MinimizeToTrayCheck = minimizeToTrayCheck.Checked; settings.AutoRunCheck = autoRunCheck.Checked; if (settings.AutoRunCheck) { using (var regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) { regkey.SetValue(Application.ProductName, Application.ExecutablePath); } } else { using (var regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) { regkey.DeleteValue(Application.ProductName, false); } } settings.RunOnTrayCheck = runOnTrayCheck.Checked; settings.Save(); }
private void Form1_Load(object sender, EventArgs e) { //ログをTextBoxに出力するためのデリゲート writeLogDelegate = WriteLog; updateRunButtonTextDelegate = UpdateRunButtonText; keyReceiver = new KeyReceiver(this); settings = Settings.Instance; portTextBox.Text = settings.Port.ToString(); if (String.IsNullOrWhiteSpace(settings.Pw)) { pwTextBox.Text = ""; } else { pwTextBox.Text = KeyContainerManager.Decrypt(settings.Pw, "KeyReceiver"); } minimizeToTrayCheck.Checked = settings.MinimizeToTrayCheck; autoRunCheck.Checked = settings.AutoRunCheck; runOnTrayCheck.Checked = settings.RunOnTrayCheck; if (runOnTrayCheck.Checked) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; runBtn_Click(sender, e); } else { notifyIcon1.Visible = false; } //ログ出力用TextBoxをReadOnlyにしたときの背景色が灰色にならないようにする Color backColor = logTextBox.BackColor; logTextBox.ReadOnly = true; logTextBox.BackColor = backColor; }