An Easy Way to Set an Autonumber in a TextBox in C#

In this tutorial, I'll show you how to set autonumber in a textbox in c #. Autonumber is very useful in programming because it generates a unique id in every transaction made. In this way, you can easily identify what kind of data you have saved in the database if you are looking for it. Let’s begin.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Do the form just like shown below. ps2

Step 3

Double click the form and set a value in a textbox in the first load of the form.
  1.  
  2. private void Form1_Load(object sender, EventArgs e)
  3. {
  4.    textBox1.Text = "0";
  5. }

Step 4

Double click the button and do the following codes to set an autonumber in a textbox. This codes will increment the number inside the textbox when the button is clicked.
  1.  
  2.         private void button1_Click(object sender, EventArgs e)
  3.         {
  4.             int txt = 1;
  5.  
  6.             txt += int.Parse(textBox1.Text);
  7.  
  8.             textBox1.Text = txt.ToString();
  9.         }
The complete source code is included you can download it and run it on your computer. For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment