private void ShowNewForm(object sender, EventArgs e) { // Create a new instance of the child form. ChildForm childForm = new ChildForm(); // Make it a child of this MDI form before showing it. childFormNumber++; childForm.MdiParent = this; childForm.Text = "Untitled " + childFormNumber; childForm.RichTextBox1.Multiline = true; childForm.RichTextBox1.Dock = DockStyle.Fill; childForm.Show(); openDoc++; windowsCountStatusLabel.Text = ("Windows Count: " + this.MdiChildren.Length); newToolStripMenuItem.Enabled = true; openToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; SaveAllToolStripMenuItem.Enabled = true; pageSetupToolStripMenuItem.Enabled = true; printPreviewToolStripMenuItem.Enabled = true; printToolStripMenuItem.Enabled = true; exitToolStripMenuItem.Enabled = true; editMenu.Enabled = true; viewMenu.Enabled = true; formatMenu.Enabled = true; windowsMenu.Enabled = true; standardToolStrip.Enabled = true; formatToolStrip.Enabled = true; }
private void OpenFile(object sender, EventArgs e) { string fn; ChildForm doc = new ChildForm(); StreamReader sr; OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); ofd.Title = "Open a Text File"; ofd.Filter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*"; DialogResult dr = ofd.ShowDialog(); fn = ofd.FileName.Trim(); if ((dr == DialogResult.Cancel)) { return; } if (ofd.CheckFileExists) { sr = File.OpenText(fn); doc.RichTextBox1.Text = sr.ReadToEnd(); sr.Close(); doc.MdiParent = this; doc.Text = ofd.FileName; doc.RichTextBox1.Multiline = true; doc.RichTextBox1.Dock = DockStyle.Fill; doc.Show(); openDoc++; windowsCountStatusLabel.Text = ("Windows Count: " + this.MdiChildren.Length); i = 1; fileMenu.Enabled = true; newToolStripMenuItem.Enabled = true; openToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; SaveAllToolStripMenuItem.Enabled = true; pageSetupToolStripMenuItem.Enabled = true; printPreviewToolStripMenuItem.Enabled = true; printToolStripMenuItem.Enabled = true; exitToolStripMenuItem.Enabled = true; editMenu.Enabled = true; viewMenu.Enabled = true; formatMenu.Enabled = true; windowsMenu.Enabled = true; standardToolStrip.Enabled = true; formatToolStrip.Enabled = true; } else { MessageBox.Show("File not found!"); } }