Change Font size at Runtime

Syedshakeer
Posted by Syedshakeer under C# category on | Views : 24786
Change Font size at Runtime using C# in Windows Application

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);
}
}


}
}

Comments or Responses

Login to post response