.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to change Font Size at RunTime windows application

Posted By:Syed Shakeer Hussain       Posted Date: February 16, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  
 

Change Font size at Runtime using C# in Windows Application. we will see step by step approach 

1) Add Two checkboxes on windows and give first checkBox name as chkboxBold and second checkBox name as chkboxItalic

2) Add one Label and name it as lbl1Text

3) then Double clik on you chkboxBold and write below code

private void chkboxBold_CheckedChanged(object sender, EventArgs e)
{
if (chkboxBold.Checked)
{
lbl1Text.Font = new Font("verdana", 12, FontStyle.Bold);

}
}

4)Next Double Click on your chkboxItalic and write below code for changing code at runtime
private void chkboxItalic_CheckedChanged(object sender, EventArgs e)
{
if (chkboxItalic.Checked)
{
lbl1Text.Font = new Font("verdana", 12, FontStyle.Italic);
}
}


in above code Checked is property to check whether a checkBox is checked or Not.
here Font can be change by using Font Class.it takes 3 arguments.

The complete code for changing Font size,Font-Family,Font Style is below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void chkboxBold_CheckedChanged(object sender, EventArgs e)
{
if (chkboxBold.Checked)
{
chkboxItalic.Checked = false;
lbl1Text.Font = new Font("verdana", 12, FontStyle.Bold);
}
}

private void chkboxItalic_CheckedChanged(object sender, EventArgs e)
{
if (chkboxItalic.Checked)
{
chkboxBold.Checked = false;
lbl1Text.Font = new Font("verdana", 12, FontStyle.Italic);
}
}


}
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend