Backspace Button in C#

Submitted by: 
Visitors have accessed this post 4322 times.

In this tutorial, I will teach you how to create a button that has a backspace function. We often click a backspace button in which this button is a keyboard key that display cursor one position backwards and deletes the character at that position, and shifts back the text after that position by one position.

So now, let's start this tutorial!

1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application and name the project as Backspace.

2. Next, add only one Button named Button1 and labeled it as "Backspace", and one TextBox named TextBox1 for us to have an inputted string. You must design your interface like this:


3. Now put this code for your code module. This code is for Button1_Click as our Backspace Button:

  1. public void Button1_Click(System.Object sender, System.EventArgs e)
  2. {
  3. if ((String.Compare(TextBox1.Text, " ") < 0) )
  4. {
  5. TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1 + 1);
  6. }
  7. else
  8. {
  9. TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1);
  10. }
  11. }

If textbox1 has a text value on it then TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1 + 1);. The Substring Function here returns a string containing a specified number of characters from a string in the textbox1 up to length of the textbox1 minus 1 + 1 of its length. Length Function here Returns an integer containing either the number of characters in a string or the nominal number of bytes required to store a variable. Otherwise if textbox1 is equal to nothing or null, then textbox1 will have its cursor be vanished.

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.



Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer

If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook:

Visit and like my page on Facebook at:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.