Skip to content

Font property of richtextbox

Rahul M

Asked Aug 18, 2009, 1:51 AM EDT2 answers
Share
LinkedInX
i made a program in which there is a checkbox which when checked it will change the property of a richtextbox to bold

can anyone please tell me how i can reset it to normal font when i uncheck the checkbox

thanking u
rahul m

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    0
    private void checkBox1_Click(object sender, EventArgs e)
    {
    if (checkBox1.Checked == true)
    {
    Font currentFont = richTextBox1.SelectionFont;
    FontStyle newFontStyle = (FontStyle)(currentFont.Style | FontStyle.Bold);
    richTextBox1.SelectionFont = new Font(currentFont.FontFamily, 7, newFontStyle);

    }
    else
    {
    Font currentFont = richTextBox1.SelectionFont;
    FontStyle newStyle = FontStyle.Regular;
    richTextBox1.SelectionFont = new Font(currentFont.FontFamily, 7, newStyle);
    }
    }
    0
  • 0
    Hi try this code......
    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
    Font font = richTextBox1.Font;
     if (checkBox1.Checked)
        richTextBox1.Font = new Font(font.FontFamily, font.Size, FontStyle.Bold);
    else
       richTextBox1.Font = new Font(font.FontFamily, font.Size, FontStyle.Regular);
    }
    0