Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
how to auto move a label left to right in c# windows Form programming
Posted

Use timer control and increment the label left position in each timer interval until it reaches the right end.
 
Share this answer
 
I took a very crude approach to do this:

1. I added the label on the form.
2. added a timer on the form.
3. set the timer timeout to 100ms.
4. added the following code to the form

C#
public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Location = new Point(label1.Location.X + 5, label1.Location.Y);

            if(label1.Location.X  > this.Width)
            {
                label1.Location = new Point(0 - label1.Width, label1.Location.Y);
            }
        }


This gave me a scrolling left to right. also it reappears on left once it goes out of form on right side.

Try it and see if you could get this to work.
 
Share this answer
 
Comments
sandeep nagabhairava 17-Jul-12 7:39am    
nice job rahul... my 5!
Member 11706275 21-May-15 21:55pm    
hai how to move the label from middle to right corner.pls any one help me its urjent.
Improve
Bhavesh Patel 28-May-15 2:44am    
Thank you...good job.
C#
private void timer1_Tick(object sender, EventArgs e)
{
    label1.Left = label1.Left + 10;
}

private void Form1_Load(object sender, EventArgs e)
{
    timer1.Enabled = true;
}
 
Share this answer
 
hi narazalok,

please go through below link that gives u idea for scrolling using jquery.

http://stackoverflow.com/questions/5988803/right-to-left-scrolling-text-effect[^]
 
Share this answer
 
Comments
Rahul Rajat Singh 17-Jul-12 3:55am    
I think the OP wants it for windows forms and not for web application.
hai how to move the label from middle to right corner.pls any one help me its urjent.
 
Share this answer
 
hi i change the code to the label go on Y row and added a pause option if you click the label

C#
//your trigger :timer1.Start();
private void timer1_Tick(object sender, EventArgs e)
{
    label2.Text ="BLAH BLAH BLAH BLAH";
    label2.Location = new Point(label2.Location.X, label2.Location.Y-2);

    if (label2.Location.Y < 0)
    {
        label2.Location = new Point(label2.Location.X, 255);
    }
}

private void label2_Click(object sender, EventArgs e)
{
    if (timer1.Enabled)
    {
        timer1.Stop();
    }
    else { timer1.Start(); }</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900