C# – Show blinking label on Windows Form
First of all many many thanks to knowledge-junction for giving me this opportunity to share my thoughts, knowledge and views. I hope our readers will find my posts helpful, knowledgeable.
This is my first blog. So I am starting with small and simple.
Recently in our project, we were required to show blinking label on window form to inform about some functionality to user. Let’s see how to get it done.
- Should have Visual Studio installed.
- Should know how to create basic visual studio windows forms application project and how to insert controls on form.
Steps: Let’s start with steps
- First of all, create a windows forms application project and give it a good name.
- Now insert label on the form and change its text according to your need.
- Add timer control to form from tool box. (Our job is not done yet!)
- When timer control is added to form, it looks like below picture
- Click on the timer1 indicated by red arrow only once and from the Properties panel set Interval property to the desired time you want. This interval time is in milliseconds. In this case it is set to 1000ms = 1s.
- Now Double click the timer1 as shown in figure 1 to add timer tick event handler. Similarly, add Form1 load event handler.
- Write the following code in timer tick event handler
- Random is a class used to generate random numbers.
- In the figure .2 randomValue.Next(0, 255) generates random number between 0 and 255. Value 255 is taken because it is the highest value for a color in 8 bit color code system.
- Set the ForeColor property of the blinking label (in this case blinkingLabel) to color structure. Method FromArgb serves the purpose to create a color structure from the specified 8 bit integer values.
- Lastly, start the timer and enable it. Write this code in form load method.
- Finally fire up your application.
If you find my blog helpful, then please like, share, comment.
Thanks for reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.