private void HourButtonClick(object sender, RoutedEventArgs e) { // Set the Display Time var sourceButton = sender as Button; var newHour = Convert.ToInt32(sourceButton.Content); DisplayTime = DisplayTime.AddHours(newHour - DisplayTime.Hour); }
private void HourGrab_MouseMove(object sender, MouseEventArgs e) { if (hourGrabMouseIsDown) { // Use positions relative to the hours display (centre is fixed with clock centre). var mousePosition = e.GetPosition(EllipseHoursAm); // Use the position to calculate the angle and hence required time var a = GetAngle(mousePosition, EllipseHoursAm.Width / 2, EllipseHoursAm.Height / 2); var hour = a / HourHandDegreesPerHour; var minutes = Math.Round(hour * 60 % 60); hour = Math.Floor(hour); // The current hour will be in the range 0 to 11 (i.e. morning). // The current display time could be morning or afternoon and if the // display time is near midnight this could be a transition to another day. var dayOffset = 0; var displayHour = DisplayTime.Hour; if (displayHour < 3 && hour > 9) { // Drag transition back a day dayOffset = -1; hour += HoursPerRevolution; // Adjust time to afternoon } else if (displayHour > 21 && hour < 3) { // Drag transition forward a day dayOffset = 1; } else if (displayHour > 9 && displayHour < 12 && hour < 3) { // Drag transition between morning and afternoon hour += HoursPerRevolution; } else if (displayHour >= 12) { // Dragging in the afternoon // Add 12 hours if not transition to am! if (!(displayHour < 15 && hour > 9)) { hour += HoursPerRevolution; } } DisplayTime = DisplayTime.AddHours(hour - DisplayTime.Hour); DisplayTime = DisplayTime.AddMinutes(minutes - DisplayTime.Minute); if (dayOffset != 0) { DisplayTime = DisplayTime.AddDays(dayOffset); } } }
private void EllipseHoursPm_MouseDown(object sender, MouseButtonEventArgs e) { mouseDownPoint = e.GetPosition(sender as IInputElement); // Use the down position to calculate the angle and hence required time var a = GetAngle(mouseDownPoint, EllipseHoursPm.Width / 2, EllipseHoursPm.Height / 2); var hour = (int)Math.Round(a / HourHandDegreesPerHour) + HoursPerRevolution; if (hour == 24) { hour = 0; } DisplayTime = DisplayTime.AddHours(hour - DisplayTime.Hour); }
private void EllipseHoursAm_MouseDown(object sender, MouseButtonEventArgs e) { mouseDownPoint = e.GetPosition(sender as IInputElement); // Use the down position to calculate the angle and hence required time var a = GetAngle(mouseDownPoint, EllipseHoursAm.Width / 2, EllipseHoursAm.Height / 2); var hour = (int)Math.Round(a / HourHandDegreesPerHour); if (hour < 1) { hour += HoursPerRevolution; } // Use right click to set afternoon if (e.ChangedButton == MouseButton.Right) { hour += HoursPerRevolution; } DisplayTime = DisplayTime.AddHours(hour - DisplayTime.Hour); }