Input for WinForms | ComponentOne
Input Controls / TextBox
In This Topic
    TextBox
    In This Topic

    C1TextBox is an input control that allows users to enter text values. It shares the common properties of all Input controls.

    Image depicting the Textbox control.

    Users can set the PlaceHolder property of C1TextBoxBase class to get or set the textual place holder, which is displayed by C1TextBox to prompt the user for information. You can also make the textbox appear multiline as shown in the snapshot by using the Multiline property.

    C#
    Copy Code
    // Configuring a textbox
                c1TextBox1.Location = new Point(10, 170);
                c1TextBox1.Size = new Size(138, 104);
                c1TextBox1.Text = "12";
                c1TextBox1.Placeholder = "Multiline";
                c1TextBox1.Multiline = true;
                c1TextBox1.TabIndex = 8;
                c1TextBox1.Text = "1 line\r\n2 line\r\n3 line\r\n4 line\r\n5 line\r\n6 line";
                c1TextBox1.PreValidation.ErrorMessage = "";
                c1TextBox1.PreValidation.Inherit = ((C1.Win.Input.PreValidationInheritProperties)((((C1.Win.Input.PreValidationInheritProperties.CaseSensitive | C1.Win.Input.PreValidationInheritProperties.ErrorMessage)
                | C1.Win.Input.PreValidationInheritProperties.TrimStart)
                | C1.Win.Input.PreValidationInheritProperties.TrimEnd)));
    

    Data Binding

    Binding a control with a data source gives you ability to communicate and even update the underlying data through the control. ComboBox can be bound to an array, enumeration or a binding source as well using the DataSource and DataMember properties of C1TextBoxBase.

    C#
    Copy Code
    c1TextBox1.DataSource = _data;
    c1TextBox1.DataMember = "FirstName";
    

    Back to Top

    Display and Edit Format

    TextBox allows you to specify two different formats, one for display (when the control is read-only or is not in the edit mode), and another for edit mode. These two formatting modes are governed by the DisplayFormat and EditFormat properties. By default, both of them inherit from the TextBox control’s properties.

    To assign a specific format type, custom format or other formatting property (see FormatInfo class) for a specific mode, change the (Inherit) flags and set the FormatType and CustomFormat properties. This breaks the inheritance from control for the FormatType property and allows us to change it.

    You can see the change in the format of the BirthDate TextBox in display and edit mode in the following GIF:

    The following code shows how you can change the TetxBox format for display and edit mode. In this example, we specify display and edit format for a TextBox named birthDateText which displays "Birth Date".

    TextBox Display and Edit Format
    Copy Code
    C1TextBox birthDateText = new C1TextBox();
    this.Controls.Add(birthDateText);
    birthDateText.Location = new System.Drawing.Point(283, 115);
    birthDateText.TabIndex = 4;
    
    // Set custom format in display mode
    birthDateText.DisplayFormat.CustomFormat = "MM/dd/yyyy";
    birthDateText.DisplayFormat.FormatType = FormatType.CustomFormat;
    //set custom format in edit format
    birthDateText.EditFormat.CustomFormat = "MM-dd-yyyy";
    birthDateText.EditFormat.FormatType = FormatType.CustomFormat;
    

    Back to Top