Ejemplo n.º 1
0
 private void NewFile_Click(object sender, EventArgs e)
 {
     if (doc != null)
     {
         doc.Close();
     }
     //窗体记录数++
     wCount++;
     //创建文档窗体对象
     doc = new DocForm();
     //设置主窗口为文档窗体的父窗口
     doc.MdiParent = this;
     //设置文档窗体的标题
     doc.Text = "文档" + wCount;
     //显示文档窗体
     doc.Show();
 }
Ejemplo n.º 2
0
        private void OpenFile_Click(object sender, EventArgs e)
        {
            if (doc != null)
            {
                doc.Close();
            }
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    RichTextBoxStreamType fileType;
                    //判断文档类型
                    switch (openFileDialog.FilterIndex)
                    {
                    case 1:
                        fileType = RichTextBoxStreamType.PlainText; break;

                    case 2:
                        fileType = RichTextBoxStreamType.RichText; break;

                    default:
                        fileType = RichTextBoxStreamType.UnicodePlainText; break;
                    }
                    wCount++;
                    doc           = new DocForm();
                    doc.MdiParent = this;
                    doc.Text      = openFileDialog.FileName;
                    doc.TxtSource.LoadFile(openFileDialog.FileName, fileType);
                    doc.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex.StackTrace, "错误");
                }
            }
        }