protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); RectangleF rect; float bezelWidth, angle; if (e.Button != MouseButtons.Left || !_IsEditable) return; bezelWidth = _ClockStyleData.BezelWidth * (ClientRectangle.Width - 1); rect = new RectangleF(ClientRectangle.X + bezelWidth, ClientRectangle.Y + bezelWidth, (ClientRectangle.Width - 1) - bezelWidth * 2.0f, (ClientRectangle.Height - 1) - bezelWidth * 2.0f); angle = RoundToExactHour((float)_Value.TimeOfDay.TotalHours * 30.0f); if (_ClockStyleData.HourHandStyle.ContainsPoint(rect, angle, e.Location)) { _LastMouseMoveHour = _Value.Hour; _NewMouseMoveHour = _Value.Hour; if (_Value.Hour > 12) _LastMouseMoveHour -= 12; _EditState = eClockEditStates.Hour; } else { angle = (float)_Value.TimeOfDay.TotalMinutes * 6.0f; if (_ClockStyleData.MinuteHandStyle.ContainsPoint(rect, angle, e.Location)) _EditState = eClockEditStates.Minute; else { angle = (float)_Value.TimeOfDay.Seconds * 6.0f; if (_ShowSecondHand && _ClockStyleData.SecondHandStyle.ContainsPoint(rect, angle, e.Location)) _EditState = eClockEditStates.Second; } } if (_EditState != eClockEditStates.None) _EditLoc = e.Location; }
protected override void OnMouseUp(MouseEventArgs e) { if (_EditState != eClockEditStates.None) { _EditLoc = e.Location; Value = GetCurrentMouseTime(); _EditLoc = Point.Empty; _EditState = eClockEditStates.None; Cursor = Cursors.Default; } base.OnMouseUp(e); }
///// <summary> ///// Occurs when subproperty value has changed. ///// </summary> //public event DevComponents.Schedule.Model.SubPropertyChangedEventHandler SubPropertyChanged; /// <summary> /// Initializes a new instance of the ClockControl class /// </summary> public AnalogClockControl() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); _AntiAlias = true; _AutomaticMode = false; _ClockStyle = eClockStyles.Style1; _ClockStyleData = new ClockStyleData(); _ClockStyleData.Parent = this; _EditState = eClockEditStates.None; _IndicatorStyle = eClockIndicatorStyles.Ticks; _IsEditable = false; _ShowGlassOverlay = true; _ShowSecondHand = true; _Value = DateTime.Now; MinimumSize = new Size((int)_BaseSize, (int)_BaseSize); ; Size = MinimumSize; }