private void btnDeleteTimer_Click(object sender, EventArgs e) { try { BLIO.Log("Attempting to delete timer..."); //First, see what button is pressed MaterialButton button = null; foreach (Control c in pnlRunningTimers.Controls) { if (c is MaterialButton) { button = (MaterialButton)c; if (button.Type == MaterialButton.MaterialButtonType.Contained) { break; } } } //Now that we have the selected button stored in the "button" variable, let's work with it //Get the id BLIO.Log("Getting the ID of the button.."); int id = GetTimerButtonId(button); BLIO.Log("Done! -> " + id + ". Getting the associated TimerItem..."); //Use the id to get the correct TimerItem from the "timers" collection, and delete it TimerItem toRemoveItem = timers.Where(t => t.ID == id).ToList()[0]; BLIO.Log("Deleting TimerItem with popup date " + toRemoveItem.PopupDate + " ..."); RemoveTimer(toRemoveItem); toRemoveItem.Dispose(); BLIO.Log("Successfully removed & disposed the TimerItem"); //Set the current timer to the first one in the list if (timers.Count > 0) { currentTimerItem = timers[0]; BLIO.Log("Setting values of (UCTimer) numericupdowns"); TimeSpan time = TimeSpan.FromSeconds((double)currentTimerItem.SecondsRemaining); numSeconds.Text = "" + time.Seconds; numMinutes.Text = "" + time.Minutes; numHours.Text = "" + time.Hours; } else //Nothing left { numSeconds.Text = "0"; numMinutes.Text = "0"; numHours.Text = "0"; btnPauseResumeTimer.Icon = Properties.Resources.pause_2x1; currentTimerItem = null; } //Set the pause/resume icon image depending on the current timer if (currentTimerItem == null || currentTimerItem.Disposed) { return; } tmrCountdown.Enabled = currentTimerItem.Running; if (currentTimerItem.Running) { btnPauseResumeTimer.Icon = Properties.Resources.pause_2x1; } else { btnPauseResumeTimer.Icon = Properties.Resources.Play; } //Now make the current TimerItem button selected foreach (Control c in pnlRunningTimers.Controls) { if (c is MaterialButton) { button = (MaterialButton)c; if (GetTimerButtonId(button) == currentTimerItem.ID) { button.Type = MaterialButton.MaterialButtonType.Contained; //This is our button } } } } catch (Exception ex) { BLIO.Log("Deleting timer FAILED. -> " + ex); BLIO.WriteError(ex, "Failed to delete this timer"); } }
private void ucTimerDeleteToolstrip_Click(object sender, EventArgs e) { //First, see what button is pressed BunifuFlatButton button = null; foreach (Control c in pnlRunningTimers.Controls) { if (c is BunifuFlatButton) { button = (BunifuFlatButton)c; if (button.Normalcolor == Color.Gray) { break; } } } //Now that we have the selected button stored in the "button" variable, let's work with it //Get the id int id = GetTimerButtonId(button); //Use the id to get the correct TimerItem from the "timers" collection, and delete it TimerItem toRemoveItem = timers.Where(t => t.ID == id).ToList()[0]; RemoveTimer(toRemoveItem); toRemoveItem.Dispose(); //Set the current timer to the first one in the list if (timers.Count > 0) { currentTimerItem = timers[0]; lblTimerTitle.Visible = true; BLIO.Log("Setting values of (UCTimer) numericupdowns"); TimeSpan time = TimeSpan.FromSeconds((double)currentTimerItem.SecondsRemaining); numSeconds.Value = time.Seconds; numMinutes.Value = time.Minutes; numHours.Value = time.Hours; } else //Nothing left { numSeconds.Value = 0; numMinutes.Value = 0; numHours.Value = 0; btnPauseResumeTimer.Iconimage = Properties.Resources.pause_2x1; lblTimerTitle.Visible = false; } //Set the pause/resume icon image depending on the current timer if (currentTimerItem.Disposed || currentTimerItem == null) { return; } tmrCountdown.Enabled = currentTimerItem.Running; if (currentTimerItem.Running) { btnPauseResumeTimer.Iconimage = Properties.Resources.pause_2x1; } else { btnPauseResumeTimer.Iconimage = Properties.Resources.Play; } //Now make the current TimerItem button selected foreach (Control c in pnlRunningTimers.Controls) { if (c is BunifuFlatButton) { button = (BunifuFlatButton)c; if (GetTimerButtonId(button) == currentTimerItem.ID) { button.Normalcolor = Color.Gray; //This is our button } } } }