TextBox Font Style, Font Color in ASP.Net C#

TextBox Font Style in C#

This asp.net textbox tutorial we will going to learn how to change textbox font style programmatically in asp.net using c#.

The below list shows style attributes of TextBox:

Style attributes Description
ForeColor It is used for set Font Color of control.
Font.Size It is used for set Font Size.
Font.Bold It is used to display a Bold text.
Font.Underline It is used to define Underline text.
Font.Italic It is used to define Italic text.
Font.Strikeout It is used to define Strikeout text.
Font.Overline
Overline text.

TextBox Font Color and Font Style C# Example

This example shows how to change programmatically TextBox font color, font size and other font style in asp.net using c#.

Font Color and Font Style in ASP.Net C# Example
Font Color and Font Style in ASP.Net C# Example

C# code for above textbox font color and style example.

    protected void btnsize17_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Size = 17;
    }
    protected void btnsize_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Size = FontUnit.Medium;
    }
    protected void btnred_Click(object sender, EventArgs e)
    {
        TextBox1.ForeColor = System.Drawing.Color.Red;
    }
    protected void btngreen_Click(object sender, EventArgs e)
    {
        TextBox1.ForeColor = System.Drawing.Color.Green;
    }
    protected void btnbold_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Bold = true;
     }
    protected void btnitalic_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Italic = true;
    }
    protected void btnunderline_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Underline = true;
    }
    protected void btnoverline_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Overline = true;
    }
    protected void btnstrike_Click(object sender, EventArgs e)
    {
        TextBox1.Font.Strikeout = true;
    }
    protected void btnnoraml_Click(object sender, EventArgs e)
    {
        TextBox1.ForeColor = System.Drawing.Color.Black;
        TextBox1.Font.Size = FontUnit.Medium;
        TextBox1.Font.Bold = false;
        TextBox1.Font.Italic = false;
        TextBox1.Font.Underline =false;
        TextBox1.Font.Overline = false;
        TextBox1.Font.Strikeout = false;
    }

In our next asp.net textbox post we will learn about border style and attributes with an example.

Leave a Reply

Your email address will not be published. Required fields are marked *