TextEditor icon indicating copy to clipboard operation
TextEditor copied to clipboard

Fix form Font

Open thanhquangqb95 opened this issue 1 year ago • 0 comments

Hi Bro. When I used your source, I found an error in the function fontToolStripMenuItem_Click(),fontToolStripMenuItem_Click, When I press exit the form still opens a new form. How I fix errors:

private void fontToolStripMenuItem_Click(object sender, EventArgs e){
try
  {
        DialogResult result = fontDialog1.ShowDialog();    // show the Font Dialog
        System.Drawing.Font oldFont = this.Font;    // gets current font
        if (result == DialogResult.OK)
        {
            fontDialog1_Apply(richTextBox1, new System.EventArgs());
        }
        // set back to the recent font
        else if (result == DialogResult.Cancel)
        {
            // set current font back to the old font
            this.Font = oldFont;
            // sets the old font for the controls inside richTextBox1
            foreach (Control containedControl in richTextBox1.Controls)
            {
                containedControl.Font = oldFont;
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); // error
    }
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
    try
    {
        DialogResult result = fontDialog1.ShowDialog();    // show the Font Dialog
        System.Drawing.Font oldFont = this.Font;    // gets current font
        if (result == DialogResult.OK)
        {
            fontDialog1_Apply(richTextBox1, new System.EventArgs());
        }
        // set back to the recent font
        else if (result == DialogResult.Cancel)
        {
            // set current font back to the old font
            this.Font = oldFont;
            // sets the old font for the controls inside richTextBox1
            foreach (Control containedControl in richTextBox1.Controls)
            {
                containedControl.Font = oldFont;
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); // error
    }
}

thanhquangqb95 avatar Apr 17 '24 18:04 thanhquangqb95