Moving text example in C#

This is a example of creating moving text in C#.
In order to do the moving text, you just need timer and label controller/component .


Steps by Step:

  1. Create one windows form project
  2. add one label in the form.
  3. copy and paste code below.
  4. Hit "CTRL + F5" and see what will happen.

The code :

    public partial class Form1 : Form
    {
        private string[] words = new string[3];
        private int i, j;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(i.Equals(words[j].Length))
            {              
                label1.Text = "";
                if (j < words.Length - 1)
                {
                    j = j + 1;
                    label1.Text = words[j];
                }
                else
                {
                    j = 0;
                }
                i = 0;
            }
            label1.Text = words[j].Substring(0, i);
            i = i + 1;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            words[0] = "www.developersnote.com";
            words[1] = "www.developersnote.com";
            words[2] = "www.developersnote.com";
            timer1.Start();
        }
    }




By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

How to create DataGrid or GridView in JSP - Servlet

Control Webpart Visible/Enable using macro in Kentico