none
Knob / POV Hat switch control

    Question

  • I admit, I use Forms with VS2008 express because the it's cheap and quick and the application I write is for internal use. OK, so here's my question: Where can I find a knob control or better,  a POV Hat switch (36000 centi-degrees)? I searched everywhere. No luck.
    Sunday, December 25, 2011 6:44 PM

Answers

  • Thank you bob for your reply.

    Isn't it strange that a knob is missing from the VS toolbox? Anyhow, I went over the controls you offered. Here are my reviews:

    Industrial Controls: Very neat and well integrated. However, does not allow 360 degree movement. Perhaps a minor problem but since I'm not a C# person I prefer not to go into this task.

    Control Knob: Did not offer demo exec and cannot compile on VS11. I drop it.

    VB.NET Knob Control: Very neat. However, impossible to add labels and no clear position indicator.

     

    What I did find, though it too has it's drawbacks is Next UI Knob Control. It can go full 360 degrees, it has optional labels. it has a position indicator. However, it is not truly continuous (It snaps to circular  grid-points) and it does not integrate into the VS design pane. I'll use it until something better appears.

     

    Tuesday, December 27, 2011 2:16 PM

All replies

  • Hi shaul_ei,
    You can try the following links:
    If this is not help, please let me know.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 27, 2011 3:03 AM
  • Thank you bob for your reply.

    Isn't it strange that a knob is missing from the VS toolbox? Anyhow, I went over the controls you offered. Here are my reviews:

    Industrial Controls: Very neat and well integrated. However, does not allow 360 degree movement. Perhaps a minor problem but since I'm not a C# person I prefer not to go into this task.

    Control Knob: Did not offer demo exec and cannot compile on VS11. I drop it.

    VB.NET Knob Control: Very neat. However, impossible to add labels and no clear position indicator.

     

    What I did find, though it too has it's drawbacks is Next UI Knob Control. It can go full 360 degrees, it has optional labels. it has a position indicator. However, it is not truly continuous (It snaps to circular  grid-points) and it does not integrate into the VS design pane. I'll use it until something better appears.

     

    Tuesday, December 27, 2011 2:16 PM
  • Hi shaul_ei,
    I’m glad to hear that you have found a Knob Control by yourself.
    I think the reason why a knob is missing from the toolbox is because there are different kinds of Knob which make it hard to fit all needs and this is not a basic control but it is not hard to achieve by ourselves.
    It is not hard to change the first control allow 360 degree movement, you just need to change the startAngle(to 0) and endAngle(to 360) in construct of LBAnalogMeter class or create properties for startAngle and endAngle(like the code below),then you can change the value in the property windows.
    [
        Category("Analog Meter"),
        Description("End Angle")
    ]
    public float EndAngle
    {
        get { return endAngle; }
        set
        {
            endAngle = value;
            Invalidate();
        }
    }
        [
        Category("Analog Meter"),
        Description("Start Angle")
    ]
    public float StartAngle
    {
        get { return startAngle; }
        set
        {
            startAngle = value;
            Invalidate();
        }
    }
    
    Here is a screenshot.
    By the way, if you are interest in custom Windows Forms Controls, you can start with MSDN Library.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, December 28, 2011 8:14 AM
  • Bob,

    I actually wanted the knob to allow continuous 360 degree rotation. So your code is not what I needed.

    However, I had to re-write two functions in file LBKnob.cs. I think they are better written now anyway.

    Here they are:

    		public virtual float GetValueFromPosition ( PointF position )
    		{
    			float degree = 0.0F;
    			float v = 0.0F;
    			float dX, dY, Radius;
    			int   Quarter=0;
    		
    			PointF center = this.KnobCenter;
    			
    			// Deltas & Radius
    			dX = position.X - center.X;
    			dY = position.Y - center.Y;
    			Radius = (float)Math.Sqrt(dX*dX + dY*dY);
    			
    			// The four Qarters
    			if ((dX >= 0) && (dY < 0))
    				Quarter = 1;
    			else
    				if ((dX >= 0) && (dY >= 0))
    					Quarter = 2;
    				else
    					if ((dX <  0) && (dY >= 0))
    						Quarter = 3;
    					else
    						if ((dX <  0) && (dY < 0))
    							Quarter = 4;
    			
    		
    			degree = (float)Math.Asin(dX/Radius)*  180F / (float)Math.PI;
    			
    			switch (Quarter)
    			{
    				case 1:
    					break;
    				case 2:
    				case 3:
    					degree = 180-degree;
    					break;
    				case 4:
    					degree += 360;
    					break;
    				default:
    					return -1F;
    			}				
    			
    			v = (degree * ( this.MaxValue - this.MinValue ) / 360F);
    		
    			if ( v > this.MaxValue )
    				v = this.MaxValue;
    		
    			if (v < this.MinValue )
    				v = this.MinValue;
    		
    			return v;					
    		}
    
    

    and:

    		public virtual PointF GetPositionFromValue ( float val )
    		{
    			PointF pos = new PointF( 0.0F, 0.0F );
    
    				
    			if ( ( this.MaxValue - this.MinValue ) == 0 )	
    				return pos;
    		
    			float _indicatorOffset = this.IndicatorOffset * this.drawRatio;
    			
    			float degree = 360F * val / ( this.MaxValue - this.MinValue );
    			degree = degree * (float)Math.PI / 180F;
    		
    			pos.X = (int)(Math.Sin(degree) * ((this.rectKnob.Width * 0.5F)- indicatorOffset ) + this.rectKnob.X + ( this.rectKnob.Width * 0.5F));
    			pos.Y = (int)(Math.Cos(degree) * -1 * ((this.rectKnob.Width * 0.5F)- indicatorOffset ) + this.rectKnob.Y + ( this.rectKnob.Height * 0.5F));
    		
    			return pos;
    		}
    
    
    Hope you find the useful.

    Thursday, December 29, 2011 8:05 PM
  • Hi shaul_ei,
    Nice code and thank you for posting it here. I think it will help others who have similar requirement.
    Have a nice day.

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 30, 2011 5:57 AM