コード例 #1
0
        public static DialogResult OpenFile(RichTextDocument doc)
        {
            OpenFileDialog ofg = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                ValidateNames   = true,
                Title           = "Open File - MDI Sample",
                Filter          = "Text files (*.rtf)|*.rtf"
            };

            if (ofg.ShowDialog() == DialogResult.OK)
            {
                doc.Location = ofg.FileName;

                try
                {
                    TextReader textReader = new StreamReader(ofg.FileName, Encoding.Default, true);
                    doc.Text = textReader.ReadToEnd();
                    textReader.Close();

                    return(DialogResult.OK);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Ошибка открытия файла!/n" + exception.Message, "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(DialogResult.Cancel);
        }
コード例 #2
0
        public RichTextEditor()
        {
            InitializeComponent();

            document = new RichTextDocument();
            document.TextChanged += new EventHandler(document_TextChanged);
        }
コード例 #3
0
        public static DialogResult OpenFile(RichTextDocument doc)
        {
            OpenFileDialog ofg = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                ValidateNames = true,
                Title = "Open File - MDI Sample",
                Filter = "Text files (*.rtf)|*.rtf"
            };

            if (ofg.ShowDialog() == DialogResult.OK)
            {
                doc.Location = ofg.FileName;

                try
                {
                    TextReader textReader = new StreamReader(ofg.FileName, Encoding.Default, true);
                    doc.Text = textReader.ReadToEnd();
                    textReader.Close();

                    return DialogResult.OK;
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Ошибка открытия файла!/n" + exception.Message, "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return DialogResult.Cancel;
        }
コード例 #4
0
        public RichTextEditor()
        {
            InitializeComponent();

            document              = new RichTextDocument();
            document.TextChanged += new EventHandler(document_TextChanged);
        }
コード例 #5
0
 public static void SaveFile(RichTextDocument doc)
 {
     if (doc.Location != String.Empty)
     {
         Save(doc);
     }
     else
     {
         SaveFileAs(doc);
     }
 }
コード例 #6
0
        private static void Save(RichTextDocument doc)
        {
            try
            {
                TextWriter textWriter = new StreamWriter(doc.Location, false);
                textWriter.Write(doc.Text);
                textWriter.Close();

                doc.isSaved = true;
            }
            catch
            {
                MessageBox.Show("Ошибка сохранения файла!", "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #7
0
        private static void Save(RichTextDocument doc)
        {
            try
            {
                TextWriter textWriter = new StreamWriter(doc.Location, false);
                textWriter.Write(doc.Text);
                textWriter.Close();

                doc.isSaved = true;
            }
            catch
            {
                MessageBox.Show("Ошибка сохранения файла!", "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        public static void SaveFileAs(RichTextDocument doc)
        {
            SaveFileDialog sfd = new SaveFileDialog()
            {
                CheckPathExists = true,
                ValidateNames   = true,
                AddExtension    = true,
                Title           = "Save File - MDI Sample",
                Filter          = "Text files (*.rtf)|*.rtf"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                doc.Location = sfd.FileName;
                RichTextDocumentSaver.Save(doc);
            }
        }
コード例 #9
0
        public static void SaveFileAs(RichTextDocument doc)
        {
            SaveFileDialog sfd = new SaveFileDialog()
            {
                CheckPathExists = true,
                ValidateNames = true,
                AddExtension = true,
                Title = "Save File - MDI Sample",
                Filter = "Text files (*.rtf)|*.rtf"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                doc.Location = sfd.FileName;
                RichTextDocumentSaver.Save(doc);
            }
        }
コード例 #10
0
 public static void SaveFile(RichTextDocument doc)
 {
     if (doc.Location != String.Empty) Save(doc);
     else SaveFileAs(doc);
 }