private void MPointToValue()
        {
            float fCapHalfWidth = 0;
            float fCapWidth     = 0;

            if (_IsRound)
            {
                fCapWidth     = _SliderLength;
                fCapHalfWidth = _SliderLength / 2.0f;
            }

            if (_Orientation == Orientation.Horizontal_LR || _Orientation == Orientation.Horizontal_RL)
            {
                float fRatio = Convert.ToSingle(mousePoint.X - fCapHalfWidth) / (Width - fCapWidth);
                _Value = Convert.ToInt32(fRatio * _Maximum);
            }
            else if (_Orientation == Orientation.Vertical_UD || _Orientation == Orientation.Vertical_DU)
            {
                float fRatio = Convert.ToSingle(mousePoint.Y - fCapHalfWidth) / (Height - fCapWidth);
                _Value = Convert.ToInt32(fRatio * _Maximum);
            }
            if (_Value < 0)
            {
                _Value = 0;
            }
            if (_Value > _Maximum)
            {
                _Value = _Maximum;
            }
            MValueChanged?.Invoke(this, new MEventArgs(_Value));
        }
Ejemplo n.º 2
0
        private void MPointToValue()
        {
            float fCapHalfWidth = 0;
            float fCapWidth     = 0;

            if (_IsRound)
            {
                fCapWidth     = _BarSize;
                fCapHalfWidth = _BarSize / 2.0f;
            }

            if (_Orientation == Orientation.Horizontal_LR)
            {
                float fRatio = Convert.ToSingle(mousePoint.X - fCapHalfWidth) / (Width - fCapWidth);
                _Value = Convert.ToInt32(fRatio * (_Maximum - _Minimum) + _Minimum);
            }
            else if (_Orientation == Orientation.Horizontal_RL)
            {
                float fRatio = Convert.ToSingle(Width - mousePoint.X - fCapHalfWidth) / (Width - fCapWidth);
                _Value = Convert.ToInt32(fRatio * (_Maximum - _Minimum) + _Minimum);
            }
            else if (_Orientation == Orientation.Vertical_UD)
            {
                float fRatio = Convert.ToSingle(mousePoint.Y - fCapHalfWidth) / (Height - fCapWidth);
                _Value = Convert.ToInt32(fRatio * (_Maximum - _Minimum) + _Minimum);
            }
            else
            {
                float fRatio = Convert.ToSingle(Height - mousePoint.Y - fCapHalfWidth) / (Height - fCapWidth);
                _Value = Convert.ToInt32(fRatio * (_Maximum - _Minimum) + _Minimum);
            }
            if (_Value < _Minimum)
            {
                _Value = _Minimum;
            }
            if (_Value > _Maximum)
            {
                _Value = _Maximum;
            }
            MValueChanged?.Invoke(this, new MEventArgs(_Value));
        }