Backspace Button in C#
Submitted by donbermoy on Tuesday, June 24, 2014 - 21:36.
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:
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.
Output:
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: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

- public void Button1_Click(System.Object sender, System.EventArgs e)
- {
- if ((String.Compare(TextBox1.Text, " ") < 0) )
- {
- TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1 + 1);
- }
- else
- {
- TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1);
- }
- }


Add new comment
- 4256 views