Skip to main content

Backspace Button in C#


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:

design

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.


Output:

design

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

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.