I'm new to this forum and C# itself.
While trying to learn some basic stuff, I stubled into a problem I just do not understand. I am trying to to output some text to a textBox char by char (using the method described in the snippets section). The problem is, that when I redirect the output to the Debug window, everything works just fine, but when I'm directing it to the textBox control, nothing happens until the loop is finished - then the desired text appears.
Here is the code I'm using:
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.Diagnostics;
using System.Threading;
namespace Typewriter_effect
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string message = "HELLO THERE!";
foreach (char x in message.ToCharArray())
{
//Debug.Write(x);
textBox1.Text += Convert.ToString(x);
System.Threading.Thread.Sleep(300);
}
}
}
}
What am I doing wrong?
Thanks!

New Topic/Question
Reply



MultiQuote







|