Question

I need to do a rotary knob control, or use one that works. I download one from that web: http://www.c-sharpcorner.com/uploadfile/desaijm/knobcontrolusingwindowsforms11182005004925am/knobcontrolusingwindowsforms.aspx but it doesn't work as I want.

I need that this knob control can make a complete circle when I move it. At the moment when you go to the max values, if you pass this value the button go automaticaly to the other value (that is 0).

All i want to do is to increment the knob rotary value all the times without a max value and not to restart to 0 when it pass the max value.

I post the code where the value change happens, but I was working on it for 3 hours and I don't know how to change... There are also two variables thar are maximum and minimum that have the max and min values of the knob.

protected override void OnMouseMove(MouseEventArgs e)
    {
        //--------------------------------------
        //  Following Handles Knob Rotating     
        //--------------------------------------
        if (this.isKnobRotating == true)
        {
            this.Cursor = Cursors.Hand;
            Point p = new Point(e.X, e.Y);
            int posVal = this.getValueFromPosition(p);
            Value = posVal;
        }       
    }

Any idea to do that or any C# control that could help me?

Thanks!

Was it helpful?

Solution

Finally I found my own solution, hope this help other people!

if (this.isKnobRotating == true)
        {
            lastValue = Value;
            this.Cursor = Cursors.Hand;
            Point p = new Point(e.X, e.Y);
            int posVal = this.getValueFromPosition(p);
            Value = posVal;
            if ((lastValue >= Maximum + radiusLeft - 1) && Value == 0)
            {
                numRounds++;
            }
            else if (lastValue <= Minimum && (Value == Maximum + radiusLeft - 1))
            {
                numRounds--;
            }
            finalValue = (Maximum + radiusLeft) * numRounds;
            result = finalValue + Value;
        }       
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top