E
E
exper1ment2018-06-02 12:53:33
C++ / C#
exper1ment, 2018-06-02 12:53:33

How to implement character-by-character output of text on a form in Sharpe (typewriter effect)?

It is necessary to implement character-by-character printed text in a label or textbox.
When you start the program, it just freezes and then displays everything at once. Tried through BeginInvoke, Threading.Thread - it doesn't work.
The last time I tried to hang a timer:

private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (char ch in textChar)
            {
                System.Threading.Thread.Sleep(10);
                textBox1.Text += ch;
                AboutBox1_Load(sender, e);
            }
        }
            }

In which direction to dig?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-06-02
@exper1ment

Because it is necessary to perform interface update operations after each added letter.
Through the timer it is necessary so:
It is necessary a temporary variable in which the text which is not deduced will be stored.
A timer called every 300 milliseconds takes the first character from this variable and appends to the text. The variable is changed to everything after the first character. If the variable becomes empty, stop the timer, since the text from the variable smoothly flows into the field.

N
netrox, 2018-06-02
@netrox

https://stackoverflow.com/questions/12390239/text-...

A
andoral, 2018-06-04
@andoral

Try to call Update on the form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question