c# - Getting a label to insert text slowly -


i trying insert text lable, text has inserted slowly/character character/letter letter, kinda in old mud games.

so far have tried doing this:

private void storybox_click(object sender, eventargs e) {     string text = storybox.text;     var index = 0;     var timer = new system.timers.timer(2000);      timer.elapsed += delegate     {         if (index < text.length)         {             index++;             storybox.text = "this should come out pretty ";         }         else         {              timer.enabled = false;              timer.dispose();         }     };      timer.enabled = true; } 

this have gathered site don't particularly understand why isn't working.

as can see it's under storybox_click.
there way automate this? when program opened, counts couple seconds , starts writing text out.

try this:

private async void button1_click(object sender, eventargs e) {     string yourtext = "this should come out pretty slowly";     label1.text = string.empty;     int = 0;     (i = 0; <= yourtext.length - 1; i++)     {         label1.text += yourtext[i];         await task.delay(500);     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -