Exemplo n.º 1
0
        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TextForm tf = (TextForm)this.ActiveMdiChild;

            tf.getRichTextBox().SelectAll();
            tf.getRichTextBox().Focus();
        }
Exemplo n.º 2
0
        private void SaveAs(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter           = "文本文件(*.txt)|*.txt|Rtf文档(*.rtf)|*.rtf";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string       FileName = saveFileDialog.FileName;
                FileStream   fs       = new FileStream(FileName, FileMode.Create);
                StreamWriter sw       = new StreamWriter(fs);

                TextForm form = (TextForm)this.ActiveMdiChild;

                try
                {
                    foreach (string line in form.getRichTextBox().Lines)
                    {
                        sw.WriteLine(line);
                    }
                    form.Text = FileName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                finally
                {
                    sw.Close();
                    fs.Close();
                }
            }
        }
Exemplo n.º 3
0
        private void 插入日期时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String   dt = System.DateTime.Now.ToString();
            TextForm tf = (TextForm)this.ActiveMdiChild;

            tf.getRichTextBox().Text += dt;
        }
Exemplo n.º 4
0
        private void saveFile(TextForm form, object sender, EventArgs e)
        {
            string fileName = form.Text;

            if (File.Exists(fileName))
            {
                FileStream   fs = new FileStream(fileName, FileMode.Open);
                StreamWriter sw = new StreamWriter(fs);
                try
                {
                    foreach (string line in form.getRichTextBox().Lines)
                    {
                        sw.WriteLine(line);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                finally
                {
                    sw.Close();
                    fs.Close();
                }
            }
            else
            {
                SaveAs(form, sender, e);
            }
        }
Exemplo n.º 5
0
 public SearchForm(TextForm tf)
 {
     InitializeComponent();
     activeForm = tf;
     this.res   = 0;
     this.rArr  = new ArrayList();
 }
Exemplo n.º 6
0
        private void ShowNewForm(object sender, EventArgs e)
        {
            TextForm childForm = new TextForm();

            childForm.MdiParent = this;
            childForm.Text      = "新建文档" + childFormNumber++;
            childForm.Show();
            //tfArr.Add(childForm);
        }
Exemplo n.º 7
0
        private void setColor(object sender, EventArgs e)
        {
            ColorDialog colorDialog = new ColorDialog();

            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                Color    color = colorDialog.Color;
                TextForm tf    = (TextForm)this.ActiveMdiChild;
                tf.getRichTextBox().ForeColor = color;
            }
        }
Exemplo n.º 8
0
        private void setFont(object sender, EventArgs e)
        {
            FontDialog fontDialog = new FontDialog();

            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                Font     font            = fontDialog.Font;
                TextForm tf              = (TextForm)this.ActiveMdiChild;
                tf.getRichTextBox().Font = font;
                printFont = font;
            }
        }
Exemplo n.º 9
0
        private void printPreview(object sender, EventArgs e)
        {
            PrintPreviewDialog ppd = new PrintPreviewDialog();
            TextForm           tf  = (TextForm)this.ActiveMdiChild;
            String             s   = tf.getRichTextBox().Text.ToString();

            lineReader = new StringReader(s);
            PrintDocument document = new PrintDocument();

            document.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
            ppd.Document        = document;
            ppd.ShowDialog();
        }
Exemplo n.º 10
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter           = "文本文件(*.txt)|*.txt|Rtf文档(*.rtf)|*.rtf";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string       str;
                string       FileName = openFileDialog.FileName;
                StreamReader sr       = new StreamReader(FileName, Encoding.Default);
                TextForm     tf       = new TextForm();
                tf.MdiParent = this;
                tf.Text      = FileName;
                tf.Show();
                while ((str = sr.ReadLine()) != null)
                {
                    tf.getRichTextBox().Text += str + '\n';
                }
            }
        }
Exemplo n.º 11
0
        private void printFile(object sender, EventArgs e)
        {
            TextForm tf = (TextForm)this.ActiveMdiChild;

            if (!File.Exists(tf.Text))
            {
                SaveAs(tf, sender, e);
            }
            StreamReader streamToPrint = null;

            try
            {
                streamToPrint = new StreamReader(tf.Text);
                TextPrintDoc tpd = new TextPrintDoc(streamToPrint);


                if (storedPageSettings != null)
                {
                    tpd.DefaultPageSettings = storedPageSettings;
                }
                PrintDialog pd = new PrintDialog();
                pd.Document = tpd;
                if (pd.ShowDialog() == DialogResult.OK)
                {
                    tpd.Print(); //打印
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            finally
            {
                streamToPrint.Close();
            }
        }
Exemplo n.º 12
0
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            TextForm form = (TextForm)this.ActiveMdiChild;

            saveFile(form, sender, e);
        }