Drag one Label on your Form and one Timer.
Insert the following code after 'InitializeComponent();
const int maximum = 100;
int actual = 0;
timer1.Interval = 100;
timer1.Enabled = true;
timer1.Tick += (sender, args) =>
{
label1.Text = (actual++ % maximum).ToString();
};
Explanation:
- Label is used to show the rolling numbers
- Timer is used to perform an operation every N miliseconds (in our case every 100ms = 0.1s)
- const int maximum = 100; // defines the maximum number we want to show
- int actual = 0; // represents the actual number we are showing at a time
- timer1.Interval = 100; // interval after which the timer1.Tick is called (in our case 100ms)
- timer1.Enabled = true; // enables the timer, without it the Tick would not get called
- timer1.Tick += (sender, args) =>
{
label1.Text = (actual++ % maximum).ToString(); // set the text to: actual + 1 modulo 100
};
EDIT: Information about modulo: https://en.wikipedia.org/wiki/Modulo_operation