Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Fix form Font #2

Description

@thanhquangqb95

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions