System.Windows.Forms.MathHelper.Step C# (CSharp) Method

Step() public static method

public static Step ( float from_value, float to_value, float speed ) : float
from_value float
to_value float
speed float
return float
        public static float Step(float from_value, float to_value, float speed)
        {
            float uSpeed = speed * Application.DeltaTime;
            if (Math.Abs(from_value - to_value) < uSpeed) return to_value;

            if (from_value < to_value)
                return from_value + uSpeed;
            else
                return from_value - uSpeed;
        }

Usage Example

        private void ApplicationOnUpdateEvent()
        {
            if (updatePos == false && Style != ProgressBarStyle.Marquee)
            {
                return;
            }

            if (Style == ProgressBarStyle.Marquee)
            {
                barWidth = marqueeWidth;
                if (barX < Width)
                {
                    barX = MathHelper.Step(barX, Width, marqueeSpeed / 2f);
                }
                else
                {
                    barX = -marqueeWidth;
                }
                return;
            }

            barX      = 0;
            barWidth  = (value / (float)maximum) * Width;
            updatePos = false;
        }
All Usage Examples Of System.Windows.Forms.MathHelper::Step