Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 131,502 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,840 people online right now. Registration is fast and FREE... Join Now!




Scrolling Text

 
Reply to this topicStart new topic

Scrolling Text

gbertoli3
post 8 Oct, 2008 - 05:49 AM
Post #1


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 1,024



Thanked 16 times

Dream Kudos: 950
My Contributions


I am trying to scroll text. I know how to scroll it in HTML Code: <marquee>Scroll Text</marquee>, but was wondering if C# has a special function like the marquee function.
User is offlineProfile CardPM

Go to the top of the page


Jayman
post 8 Oct, 2008 - 06:15 AM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,819



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


No there is not, at least that I am aware of. You are going to have to implement this functionality yourself.
User is offlineProfile CardPM

Go to the top of the page

gbertoli3
post 8 Oct, 2008 - 06:26 AM
Post #3


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 1,024



Thanked 16 times

Dream Kudos: 950
My Contributions


Ok Thanks
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 8 Oct, 2008 - 07:55 AM
Post #4


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,371



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


To scroll a label, all you have to do is change the location:
csharp
		public void ScrollingLabel(Label l) {
for (int i = l.Location.X; i >= 0; i--) {
l.Location = new Point(l.Location.X-1, l.Location.Y);
System.Threading.Thread.Sleep(50);
}
}


The problem is, it'll take over all control (It's in a loop, nothing else can be processed)

One way to do it would be to put it in a thread, using Invoke like I showed you before.

smile.gif
User is offlineProfile CardPM

Go to the top of the page

eclipsed4utoo
post 8 Oct, 2008 - 09:05 AM
Post #5


D.I.C Regular

***
Joined: 21 Mar, 2008
Posts: 307



Thanked 16 times
My Contributions


I had to do this for a customer... this will scroll text inside of a textbox by removing the first character and placing it at the end of the string.

delegate for scrolling and class level variable
csharp

public delegate void ScrollTextboxCallback(string t);
string marqueeText = "This is only a test.";


Tread to start the marquee
csharp

Thread thread = new Thread(new ThreadStart(ScrollTextbox));
thread.Start();


ScrollTextbox method
csharp

private void ScrollTextBox()
{
string tempChar = string.Empty;
string tempText = string.Empty;
tempText = marqueeText + " "; // adds spaces at the end of the text so there is a clear ending to the text

while (true)
{
tempChar = tempText.SubString(0,1);
tempText = tempText.Remove(0,1) + tempChar;
textBox1.Invoke(new ScrollTextboxCallback(this.UpdateTextBox), new object[] { tempText });
Thread.Sleep(100); //lowering this value with make the marquee scroll faster
}
}


UpdateTextBox method
csharp

private void UpdateTextBox(string m_text)
{
textBox1.Text = m_text;
}


This post has been edited by eclipsed4utoo: 8 Oct, 2008 - 09:07 AM
User is offlineProfile CardPM

Go to the top of the page

gbertoli3
post 8 Oct, 2008 - 02:08 PM
Post #6


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 1,024



Thanked 16 times

Dream Kudos: 950
My Contributions


Thanks Guys!
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 12:27AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month