C# – Show blinking label on Windows Form

Hi all,

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.

Prerequisites:

  1. Should have Visual Studio installed.
  2. 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

  1. First of all, create a windows forms application project and give it a good name.
  2. Now insert label on the form and change its text according to your need.
  3. Add timer control to form from tool box. (Our job is not done yet!)
  4. When timer control is added to form, it looks like below picture
Inserting_Timer

Figure .1 Adding Timer to a form

  1. 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.
  2. Now Double click the timer1 as shown in figure 1 to add timer tick event handler. Similarly, add Form1 load event handler.
  3. Write the following code in timer tick event handler
Tick_Code

Figure .2 Tick even handler

  1. Random is a class used to generate random numbers.
  2. 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.
  3. 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.
  4. Lastly, start the timer and enable it. Write this code in form load method.

    Start_timer

    Figure .3 Start and enable Timer

  5. 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.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading