How to Blink the Text in Windows Form Applications using with Timer control in C#.net ||Basic Timer control Example with window forms in C#.net



To blink the text with in time period in window forms using Timer control follow the steps:

1.  Open the Visual Studio 2010-->File -->New-->Project-->Select Windows Form Application         -->ClickOK

2. Design the form from  Tool Box first take one Label and one Timer Control.

3. Change the Timer and Label Names.

4. Double click on Timer control then Write the Below Code in Form1.CS  File

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{

    public partial class Form1 : Form
    {
      
        private const int _blinkFrequency = 250;

        private const int _maxNumberOfBlinks = 1000;

        private int _blinkCount = 0;
       
       public Form1()
        {
            InitializeComponent();

            timer1.Interval = _blinkFrequency; //optional: set in design code
            label1.Text = "Welcome ";
           
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
            this.label1.Visible = !this.label1.Visible;

            _blinkCount++;
         

            if (_blinkCount == _maxNumberOfBlinks * 2)
            {

                timer1.Stop();

                label1.Visible = true;

              
            }
        }
       
    }
}

 5. Run your application then you will get output like below:




0 comments:

Post a Comment