NearestValueFromPoint() public method

Find nearest value given the mouse postion within track area.
public NearestValueFromPoint ( Point pt ) : int
pt Point Mouse position,
return int
Example #1
0
        /// <summary>
        /// Mouse has moved inside the view.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="pt">Mouse position relative to control.</param>
        public virtual void MouseMove(Control c, Point pt)
        {
            if (_captured)
            {
                // Only interested if the mouse is over the track area
                if (_drawTB.ClientRectangle.Contains(pt))
                {
                    // Ignore multiple calls with the same point
                    if (_lastMovePt != pt)
                    {
                        _lastMovePt = pt;

                        _targetValue = _drawTB.NearestValueFromPoint(pt);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Mouse has moved inside the view.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="pt">Mouse position relative to control.</param>
        public virtual void MouseMove(Control c, Point pt)
        {
            if (_captured)
            {
                // Only interested if the mouse is over the track area
                if (_drawTB.ClientRectangle.Contains(pt))
                {
                    // Ignore multiple calls with the same point
                    if (_lastMovePt != pt)
                    {
                        _lastMovePt = pt;

                        // Restart the timer
                        _repeatTimer.Stop();
                        _repeatTimer.Start();

                        // Only use newly calculated target value if in correct direction
                        int newTargetValue = _drawTB.NearestValueFromPoint(pt);
                        int currentValue   = _drawTB.ViewDrawTrackBar.Value;
                        if (_targetHigher)
                        {
                            if (newTargetValue > currentValue)
                            {
                                _targetValue = newTargetValue;
                            }
                        }
                        else
                        {
                            if (newTargetValue < currentValue)
                            {
                                _targetValue = newTargetValue;
                            }
                        }

                        OnRepeatTimer(_repeatTimer, EventArgs.Empty);
                    }
                }
            }
        }
        /// <summary>
        /// Mouse has moved inside the view.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="pt">Mouse position relative to control.</param>
        public virtual void MouseMove(Control c, Point pt)
        {
            if (_captured)
            {
                // Ignore multiple calls with the same point
                if ((_lastMovePt != pt))
                {
                    _lastMovePt = pt;

                    // Find the new target value given mouse position
                    int newTargetValue = _drawTB.NearestValueFromPoint(pt);

                    // If this is a change in value then update now
                    if (_drawTB.ViewDrawTrackBar.Value != newTargetValue)
                    {
                        _drawTB.ViewDrawTrackBar.ScrollValue = Math.Max(_drawTB.ViewDrawTrackBar.Minimum, Math.Min(newTargetValue, _drawTB.ViewDrawTrackBar.Maximum));
                    }
                }
            }
        }