Monday, 6 January 2020

Textbox Controls in C# | Visual Studio 2019

Introduction to C# Programming:


Text Control in C#:

C# TextBox is used to get input from users or it can also be used to display some values to the user. The textbox is a container for text blocks, you can take inputs or show the text as you required in the form of paragraphs. If you used TextBox as the input field then you can only take one line of text as the input but if you want multiple line input then you have to activate the multiple line property of C# TextBox.

A simple Program showing Textbox Controls:

STEP 1 - Start the ProjectLet's create a new project using Visual Studio 2019.
Select New Project-->Visual C#--->Windows Forms App (.NET Framework), give your project a name and click Create.
STEP 2 - Drag and Drop ControlLet's add a TextBox control to the form by dragging it from Toolbox and dropping it to the form. You will see a TextBox 1 is added to the form. This control is now available to you in the code behind.

Now, let's add another control to the form by dragging the other control from Toolbox to the form. You may also want to change the properties of the other controls. Let's add a Label and a Button control to the form.
STEP 3 - Coding for Button Click Event

 using System;  
 using System.Collections.Generic;  
 using System.ComponentModel;  
 using System.Data;  
 using System.Drawing;  
 using System.Linq;  
 using System.Text;  
 using System.Threading.Tasks;  
 using System.Windows.Forms;  
 namespace WindowsFormsApp1  
 {  
   public partial class Form1 : Form  
   {  
     public Form1()  
     {  
       InitializeComponent();  
     }  
     private void Form1_Load(object sender, EventArgs e)  
     {  
     }  
     private void btn_get_Click(object sender, EventArgs e)  
     {  
       MessageBox.Show(txt_time.Text);  
     }  
     private void btn_set_Click(object sender, EventArgs e)  
     {  
       txt_time.Text = DateTime.Now.ToString();  
     }  
   }  
 }  
YouTube Video Link:
https://www.youtube.com/watch?v=C2cYlqJY1U4

No comments:

Post a Comment

Textbox Controls in C# | Visual Studio 2019

Introduction to C# Programming: Text Control in C#: C# TextBox  is used to get input from users or it can also be used to display s...