private void AddToProfileList(Profile profile) { profileBindingSource.Add(profile); //Something about the deseralisation process causes the hotkeys to not work //Have to do this to resolve it if (profile.Hotkey != null) profile.Hotkey = new Hotkey(profile.Hotkey.KeyCode, profile.Hotkey.Shift, profile.Hotkey.Control, profile.Hotkey.Alt, false); RegisterHotkey(profile); }
private string SerialiseProfile(Profile profile) { IFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, profile); stream.Position = 0; BinaryReader br = new BinaryReader(stream); byte[] bytes = br.ReadBytes((int)stream.Length); return Convert.ToBase64String(bytes); }
private Profile ChangeToProfile(Profile selection) { if (File.Exists(selection.Path)) { MonitorSwitcher.LoadDisplaySettings(selection.Path); } else { if (MessageBox.Show("Profile not found. Delete profile?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes) { bDelete_Click(null, null); } } return selection; }
private void RegisterHotkey(Profile selection) { if (selection.Hotkey != null && !selection.Hotkey.Registered) { selection.Hotkey.Register(this); selection.Hotkey.Pressed += delegate { ChangeToProfile(selection); }; } }
private void bSaveProfile_Click(object sender, EventArgs e) { if(sfdProfileXML.ShowDialog() == System.Windows.Forms.DialogResult.OK) { MonitorSwitcher.SaveDisplaySettings(sfdProfileXML.FileName); //Seralise the information Profile profile = new Profile { Name = Path.GetFileNameWithoutExtension(sfdProfileXML.FileName), Path = sfdProfileXML.FileName }; string serialisedProfile = SerialiseProfile(profile); AddToProfileList(profile); Properties.Settings.Default.Profiles.Add(serialisedProfile); Properties.Settings.Default.Save(); } }