I have Form1, RichTextBox1 and Button1 on my Form
To understand what i’m trying to do; take a look at this link, type in a facebook profile link and click on Hack Account AND SEE THE GREEN TEXT THAT APPEARS
I’m using the code below in C# to achieve what i want to do :
private void button1_Click(object sender, EventArgs e)
{
string myStr = "This is a test string to stylize your RichTextBox1";
foreach (char c in myStr.ToCharArray()) {
Thread.Sleep(100);
richTextBox1.AppendText(c.ToString());
}
}
But it doesn’t work, the text appears in the text box at one time; Not char by char!
The reason your code is showing all the text at once is using Thread.Sleep() keep the main Thread (the UI thread) suspended / sleep mode, so none of the Application message are processed on form & the form paint / drawing event are not doing the job as the UI thread is sleeping/suspended!
Solution 1: Use a helper Thread so that Thread.Sleep() dont make ur app go in non-responsive mode
Solution # 2 : Use a timer