TextBox Control in C#

In this tutorial we will learn how to create textbox in windows form and usage of textbox controls in visual studio.

Let's create windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create a TextBox then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "TextBox".

create textbox control

Let's know about textbox public properties

  1. Name : when you change the Name of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox name
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Name = "TextBoxUserName"; 
    }
    
  2. BackColor : when you change the BackColor of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox backcolor
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.BackColor = Color.Black;
    }
    
  3. BorderStyle : when you change the BorderStyle of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox borderstyle
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.BorderStyle = BorderStyle.FixedSingle;
    }
    
  4. CharacterCasing : when you change the CharacterCasing of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox charactercasing
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.CharacterCasing = CharacterCasing.Upper;
    }
    
  5. Cursor : when you change the Cursor of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox cursor
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Cursor = Cursors.Hand;
    }
    
  6. Dock : when you change the Dock of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox dock
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Dock = DockStyle.Top;
    }
    

    Basically, Dock defines which border of the control are bound to the container.

  7. Enabled : when you change the Enabled of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox enabled
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Enabled = false;
    }
    
  8. Font : when you change the font of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox font
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Font = new Font("Cursive", 9.0F, FontStyle.Bold);
    }
    
  9. ForeColor : when you change the forecolor of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox forecolor
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.ForeColor = Color.Blue;
    }
    
  10. Location : when you change the location of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox location
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Location = new Point(10,10);
    }
    
  11. MaxLength : when you change the max length of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox maxlength
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.MaxLength = 2;
    }
    
  12. Modifiers : when you change the modifiers of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox modifiers

    Basically, modifiers indicates the visibility level of the object

  13. Multiline : when you change the multiline of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox multiline
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Multiline = true;
    }
    
  14. PasswordChar : when you change the passwordchar of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox passwordchar
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.PasswordChar = '#';
    }
    
  15. ReadOnly : when you change the readonly of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox readonly
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.ReadOnly = true;
    }
    
  16. RightToLeft : when you change the righttoleft of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox righttoleft
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.RightToLeft = RightToLeft.Yes;
    }
    
  17. ScrollBars : when you change the "ScrollBars" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox ScrollBars
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.ScrollBars = ScrollBars.Horizontal;
    }
    
  18. Size : when you change the "Size" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox Size
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Width = 100;
        txtboxUser.Height = 30;
    }
    
  19. TabIndex : when you change the "TabIndex" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox TabIndex
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.TabIndex = 1;
    }
    
  20. TabStop : when you change the "TabStop" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox TabStop
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.TabStop = true;
    }
    
  21. Text : when you change the "Text" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox Text
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Text = "Hello World";
    }
    
  22. TextAlign : when you change the "TextAlign" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox TextAlign
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.TextAlign = HorizontalAlignment.Right;
    }
    
  23. UseSystemPasswordChar : when you change the "UseSystemPasswordChar" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox UseSystemPasswordChar
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.UseSystemPasswordChar = true;
    }
    
  24. UseWaitCursor : when you change the "UseWaitCursor" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox UseWaitCursor
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.UseWaitCursor = true;
    }
    
  25. Visible : when you change the "Visible" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox Visible
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.Visible = true;
    }
    
  26. WordWrap : when you change the "WordWrap" of textbox then you select the "TextBox" = > right click on TextBox = > select Properties

    change textbox WordWrap
    private void Form1_Load(object sender, EventArgs e)
    {
        txtboxUser.WordWrap = true;
    }
    


Write a comment


Name Email Message