Thursday 19 April 2012

How to use Marquee in Window forms using Timer control

To apply a marquee on 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;
using System.Data.SqlClient;

namespace Marqueelabelin_Winform
{
    public partial class Form1 : Form
    {
        private int xPos = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Width == xPos)
            {
                //repeat marquee
                this.label1 .Location = new System.Drawing.Point(0, 40);
                xPos = 0;
            }
            else
            {
                this.label1.Location = new System.Drawing.Point(xPos, 40);
                xPos++;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
             
                 lblText.Text = "ALLEN";
                 timer1.Start();
          

        }
    }
}


 

6 comments:

  1. thank u for Marquee code...
    and i need one more help from u
    how to retrieve data from UART serial port RS232(data from sensor) in C# GUI windows application

    ReplyDelete
    Replies
    1. reply me with code with example to mail ......
      siddaram.patilglb@gmail.com

      Delete
    2. reply me with code with example to mail ......
      siddaram.patilglb@gmail.com

      Delete
  2. thank u for Marquee code...
    and i need one more help from u
    how to retrieve data from UART serial port RS232(data from sensor) in C# GUI windows application

    ReplyDelete