Windows Forms - Encode And Decode

In this article, we will discuss how to encode and decode the textbox values in a Windows form.

Step 1

Click New >> Project >> Visual C# >> Windows >> Windows Forms Application. Enter your project name and click OK.

Windows Forms

Step 2

Click View -> Toolbox for using the toolbox to design the Form in the Window application.

Windows Forms

Step 3

Click the Button properties and add the button1_Click Event to make the function accurate.

  1. privatevoid button1_Click(object sender, EventArgs e) {  
  2.     string _string = textBox1.Text;  
  3.     string _encode = "";  
  4.     for (inti = 0; i < _string.Length; i++) {  
  5.         _encode += (char)(_string[i] + 10);  
  6.     }  
  7.     textBox2.Text = _encode;  
  8. }  
  9. privatevoid button2_Click(object sender, EventArgs e) {  
  10.     string _decodestring = textBox3.Text;  
  11.     string _decode = "";  
  12.     for (inti = 0; i < _decodestring.Length; i++) {  
  13.         _decode += (char)(_decodestring[i] - 10);  
  14.     }  
  15.     textBox4.Text = _decode;  
  16. }  

Step 4

Press F5 or "Build and Run" the application to get the data encrypted and decrypted.

Windows Forms
Ebook Download
View all
Learn
View all