I have to create a marquee in a .NET windows application. What is the best to do this with C#?
-
2I understood the question as a marquee selection, but other people seem to have different ideas. Can you be more specific? – Xavier Poinas Jun 3 '11 at 6:10
-
Can you go through your other questions and see mark any answers that correctly helped you, as the accepted answer. This will give rep to those who help you and yourself, which encourages other people to help. – Bryan Jun 3 '11 at 6:30
-
Please clarify: Marquee = scrolling text OR styled progress bar OR something else? – Greg Jun 3 '11 at 6:40
-
@bryan:what do u mean.i am not getting what do u want to say exactly? – Lalit Kandpal Jun 3 '11 at 8:09
here is the simple code on how you can do marquee in C#
private int xPos=0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Width == xPos)
{
//repeat marquee
this.lblMarquee.Location = new System.Drawing.Point(0, 40);
xPos = 0;
}
else
{
this.lblMarquee.Location = new System.Drawing.Point(xPos, 40);
xPos++;
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
Just place a ProgressBar
control and change its Style
to Marquee
from the designer. You'll see the animation immediately.
If you're referring to text marquee, just place a Label
control and user the Timer Class to increment the Location.X
property of the label. When X coordinate is equal to the size of the control, just reset it and start over.
private void button_Click(object sender, EventArgs e)
{
int j = 100;
for (int i = 0; i < j; i++)
{
Thread.Sleep(5);
label3.Location = new System.Drawing.Point(0 + i, 111);
label3.Visible = true;
}
for (int i = j; i-- > 0; )
{
Thread.Sleep(15);
label3.Location = new System.Drawing.Point(0 + i, 111);
label3.Visible = true;
if (i < 1)
button_Click(sender, e);
}
}