Increase Decrease font size programmatically

Write a program to increase and decrease font size programmatically.

HTML

 

    
<%--//==== Label to shwo output.--%> <%--//==== Font-Size="10" is used to set the initial font size.--%>
<%--//==== Button to Decrease font size.--%>   <%--//==== Button to Increase font size.--%>

 

Code Behind:

 

protected void btnDecreaseFont_Click(object sender, EventArgs e)
    {
        //==== Get the current font size of the lable and remove pt concated with font size.
        int currentSize = Convert.ToInt32(lblOutput.Font.Size.ToString().Replace("pt",""));

        //==== Decrease font size by 1pt.
        lblOutput.Font.Size = currentSize - 1;
    }
    protected void btnIncreaseFont_Click(object sender, EventArgs e)
    {
        //==== Get the current font size of the lable and remove pt concated with font size.
        int currentSize = Convert.ToInt32(lblOutput.Font.Size.ToString().Replace("pt", ""));

        //==== Increase font size by 1pt.
        lblOutput.Font.Size = currentSize + 1;
    }

 


Final Output:

 Increase-Decrease-font-size-programmatically-asp-net-practical-question-codingfusion

 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice