Creating a Typewriter Effect in .NET


I'm an aspiring writer. My ultimate dream is to become a famous writer, retire, open a coffee shop in a nice little quaint town, and write more. Yes, I know, it may be a pipe dream, but who knows? Perhaps it will work out.

I have always wanted a typewriter, but alas, it will have to wait. Because I do not have my own typewriter yet, I have decided to create this article. In this article, you will learn how to mimic a typewriter's behaviour.


Open Visual Studio and create a new C# or Visual Basic.NET Windows Forms project. There is not much of a design. There is only one RichTextBox on the form and it is docked.

Figure 1: Design

There isn't much code, but I do hope you forgive me. As usual, add the necessary Namespaces to your code.


using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;


Imports System.Threading

The System.Threading namespace allows you to spawn different threads in your applications. If you do not know anything about threading, you may want to read this article before continuing: Introduction to Threading and VB.NET The article covers the ins and outs of basic threading.

Add the following sub procedure to your Form's code.


   private void TypeWords(string strInput)
      string[] ArrWords = strInput.Split(' ');

      Task t = Task.Run(() =>

         foreach (string strWord in ArrWords)

            foreach (char chrLetter in strWord)







   Private Sub TypeWords(ByVal strInput As String)

      Dim ArrWords As String() = strInput.Split(" "c)

      Dim t As Task = Task.Run(Sub()

         For Each strWord As String In ArrWords

            For Each chrLetter As Char In strWord




      End Sub)

   End Sub

The TypeWords Sub procedure accepts a string as an argument. ArrWords is an array that splits the input string at each space. A new task gets spawned; this makes use of the Threading classes to pause displaying the character. This gives the delayed effect an ordinary typewriter has.

Call this sub procedure from your RichTextBox's KeyUp event.


   private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
      if (!String.IsNullOrEmpty(richTextBox1.Text))





   Private Sub richTextBox1_KeyUp(sender As Object, _
            e As KeyEventArgs) Handles richTextBox1.KeyUp

      If Not String.IsNullOrEmpty(richTextBox1.Text) Then


      End If

   End Sub

If there is valid input, the TypeWords sub procedure will be called.

When running this application, your screen (after some input) will resemble Figure 2.

Figure 2: Running


I think it is quite apparent that I am a lazy guy and that I didn't have much work to do. Times like these enable me to conjure up funky little apps such as this one. I sincerely hope you have enjoyed it. Happy coding!

This article was originally published on September 19th, 2018

About the Author

Hannes DuPreez

Hannes du Preez is a self-taught developer who started learning to program in the days of QBasic. He has written several articles over the years detailing his programming quests and adventures. .NET is his second love, just after his wife and kid. He has always been an avid supporter of .NET since the beginning and is an expert in VB and C#. He was given the Microsoft Most Valuable Professional Award for .NET (2008–2017). He has worked as a moderator and an article reviewer on online forums and currently works as a C# developer and writes articles for CodeGuru.com, Developer.com, DevX.com, and the Database journal.
His first book Visual Studio 2019 In Depth is currently on sale on Amazon and Bpb Publications.

You could reach him at: ojdupreez1978[at]gmail[dot]com

Related Articles

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date