TextBox Control in (C#) With Example

TextBox control accepts input in a single line only. To make it multi-line, you need to set Multiline property to true. By default, the Multiline property is false. When you drag and drop a TextBox control from Toolbox to a Form, you cannot change the height of a TextBox control.


Background Color and Foreground Color
You can set background color and foreground color through property window and programmatically.
Example:-    

{
 textBox1.BackColor = Color.Blue;

 textBox1.ForeColor = Color.White;

}
Output:-
Textbox BorderStyle:-
You can set 3 different types of border style for textbox, they are None, FixedSingle and fixed3d. 
{
                        textBox1.BorderStyle = BorderStyle.Fixed3D;
}
Textbox Maximum Length:-
Sets the maximum number of characters or words the user can input into the text box control.   
{
   textBox1.MaxLength = 40;
}
Textbox ReadOnly:-
When a program wants to prevent a user from changing the text that appears in a text box, the program can set the controls Read-only property is to True.
{
  textBox1.ReadOnly = true;
}
Multiline TextBox:-
You can use the Multiline and ScrollBars properties to enable multiple lines of text to be displayed or entered. 

{    
textBox1.Multiline = true;
}
Textbox passowrd character:-
TextBox controls can also be used to accept passwords and other sensitive information. You can use the PasswordChar property to mask characters entered in a single line version of the control
{
textBox1.PasswordChar = '*';
}



Example:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TEXTBOXeXAMPLE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Blue;
            textBox1.ForeColor = Color.White;
            textBox1.BorderStyle = BorderStyle.Fixed3D;
            textBox1.Multiline = true;
            textBox1.MaxLength = 40;


        }
    }
}

Comments