private void ButtonApply_Click(object sender, EventArgs e) { // Save profiles ProfileManager.SaveProfiles(); // Update fallback profile fallbackProfile = new Profile("", MouseParams.GetSpeed(), MouseParams.GetAcceleration()); // Refresh displayed settings RefreshCurrentSettings(); }
private void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { // Get current mouse parameters int speed = MouseParams.GetSpeed(); bool acceleration = MouseParams.GetAcceleration(); // Remove old items contextMenuStrip.Items.Clear(); // Add top items contextMenuStrip.Items.AddRange(toolStripMenuItemsTop); // Check whether mouse profiles exist ProfileManager.LoadProfiles(); if (ProfileManager.Profiles.Count > 0) { // Store number of items at top of menu for use as index shift correction int shift = toolStripMenuItemsTop.Count(); // Add an item for each mouse profile for (int i = 0; i < ProfileManager.Profiles.Count; i++) { Profile profile = ProfileManager.Profiles[i]; // Include the index as the name property of the item for identification string text = (profile.Name == null || profile.Name.Trim() == "") ? "Untitled profile" : profile.Name.Trim(); contextMenuStrip.Items.Add(new ToolStripMenuItem(text, null, null, i.ToString())); // Check item if associated profile is active if (contextMenuStrip.Items[shift + i] is ToolStripMenuItem item) { item.Checked = profile.Speed == speed && profile.Acceleration == acceleration; } } } else { // Add item with useful message contextMenuStrip.Items.Add(new ToolStripMenuItem("No saved profiles", null)); } // Add bottom items contextMenuStrip.Items.AddRange(toolStripMenuItemsBottom); // Set cancel to false // By default this is set to true for optimisation if unspecified e.Cancel = false; }
// Constructors public ProfileForm() { // Store current profile fallbackProfile = new Profile("", MouseParams.GetSpeed(), MouseParams.GetAcceleration()); // Initialise form (designer code) InitializeComponent(); Text = Application.ProductName; // Initialise data grid DataGridViewProfiles(); // Initialise menu strip toolStripMenuItemAbout.Text = "&About " + Application.ProductName; // Display current mouse settings RefreshCurrentSettings(); // Assign event handlers FormClosing += ProfileForm_FormClosing; buttonApply.Click += ButtonApply_Click; buttonCancel.Click += ButtonCancel_Click; buttonDonate.Click += ButtonDonate_Click;; buttonOK.Click += ButtonOK_Click; buttonRefresh.Click += ButtonRefresh_Click; dataGridViewProfiles.CellClick += DataGridViewProfiles_CellClick; dataGridViewProfiles.CellPainting += DataGridViewProfiles_CellPainting; dataGridViewProfiles.CellValueChanged += DataGridViewProfiles_CellValueChanged; dataGridViewProfiles.CurrentCellDirtyStateChanged += DataGridViewProfiles_CurrentCellDirtyStateChanged; dataGridViewProfiles.DataError += DataGridViewProfiles_DataError; dataGridViewProfiles.EditingControlShowing += DataGridViewProfiles_EditingControlShowing; dataGridViewProfiles.RowPostPaint += DataGridViewProfiles_RowPostPaint; dataGridViewProfiles.RowsAdded += DataGridViewProfiles_RowsAdded; dataGridViewProfiles.RowsRemoved += DataGridViewProfiles_RowsRemoved; toolStripMenuItemAbout.Click += ToolStripMenuItemAbout_Click; toolStripMenuItemDonate.Click += ToolStripMenuItemDonate_Click; toolStripMenuItemOptions.Click += ToolStripMenuItemOptions_Click; // Load saved profiles and reset bindings for data grid ProfileManager.LoadProfiles(); bindingSourceProfiles.ResetBindings(false); }
public void ShowActiveProfiles() { // Get current mouse parameters int speed = MouseParams.GetSpeed(); bool acceleration = MouseParams.GetAcceleration(); // Unassign event handler to prevent StackOverFlowException on subsequent cell value changes dataGridViewProfiles.CellValueChanged -= DataGridViewProfiles_CellValueChanged; // Go through each row and show whether the corresponding profile is active foreach (DataGridViewRow row in dataGridViewProfiles.Rows) { if (!row.IsNewRow) { row.Cells[columnActive.Index].Value = (int)row.Cells[columnSpeed.Index].Value == speed && (bool)row.Cells[columnAcceleration.Index].Value == acceleration; } } // Reassign event handler dataGridViewProfiles.CellValueChanged += DataGridViewProfiles_CellValueChanged; }
public void RefreshCurrentSettings() { // Display the current mouse settings textBoxSpeed.Text = MouseParams.GetSpeed().ToString(); textBoxAcceleration.Text = MouseParams.GetAcceleration().ToString(); }
/// <summary> /// Sets the mouse speed of this profile to the nearest valid mouse speed. /// </summary> public void ValidateSpeed() { Speed = MouseParams.ValidateSpeed(Speed); }
// Methods /// <summary> /// Applies this profile. /// </summary> public void Apply() { MouseParams.SetSpeed(Speed); MouseParams.SetAcceleration(Acceleration); }
/// <summary> /// Initialises a new instance of the <see cref="Profile"/> class with the specified properties. /// </summary> /// <param name="name">the name of this profile.</param> /// <param name="speed">the mouse speed of this profile.</param> /// <param name="acceleration">the mouse acceleration state of this profile.</param> public Profile(string name, int speed, bool acceleration) { Name = name; Speed = MouseParams.ValidateSpeed(speed); Acceleration = acceleration; }