Input for WinForms | ComponentOne
Appearance and Styling / Masked Textbox
In This Topic
    Masked Textbox
    In This Topic

    Input provides various properties for customizing the appearance and styling the Masked Textbox control, so that you can generate the MaskedTextBox control as per your requirement and change the look and feel of the application you are creating.

    Appearance

    The C1MaskedTextBox class allows you to enhance the appearance of the TextBox control, such as changing the forecolor, adding an icon or placeholder etc.

     

    The code snippet below depicts how to use appearance-related properties in Masked Textbox:

    C#
    Copy Code
    // Change the appearance of Masked Textbox
    c1MaskedTextBox1.ForeColor = System.Drawing.Color.MediumSeaGreen;
    c1MaskedTextBox1.Icon = new C1.Framework.C1BitmapIcon(null, new System.Drawing.Size(16, 16), System.Drawing.Color.Transparent, Image.FromFile(@"resources\OIP (7).jpg"));
    c1MaskedTextBox1.Placeholder = "Enter phone number";
    

    Styling

    Let's explore how to use styling properties to style the UI of the Masked TextBox control.

    The C1MaskedTextBox class provides the BackColor and ForeColor properties to set the background and foreground colors, respectively. Besides these, it also provides the Styles property to apply styling to different states of textbox such as Default, Disabled, Hot, HotPressed, and Pressed.

    The following image showcases styling applied to the Masked TextBox control.

    To apply styling to the Masked TextBox control, use the following code. Here, we apply styling to the Masked TextBox control by setting the background color, foreground color, font style and borders.

    C#
    Copy Code
    // Style Masked Textbox
    c1MaskedTextBox1.BackColor = System.Drawing.Color.AntiqueWhite;
    c1MaskedTextBox1.Styles.Hot.BackColor = System.Drawing.Color.Yellow;
    c1MaskedTextBox1.ForeColor = Color.Purple;
    //Style font
    c1MaskedTextBox1.Font = new System.Drawing.Font("Segoe UI", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
    //Set border
    c1MaskedTextBox1.Styles.Default.BorderColor = System.Drawing.Color.DarkOrange;
    c1MaskedTextBox1.Styles.Border = new C1.Framework.Thickness(2, 2, 2, 2);