コード例 #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
ファイル: RtdSaver.cs プロジェクト: Krium/WORDPAD
 public static void SaveFile(RichTextDocument doc)
 {
     if (doc.Location != String.Empty)
     {
         Save(doc);
     }
     else
     {
         SaveFileAs(doc);
     }
 }
コード例 #3
0
ファイル: RtdSaver.cs プロジェクト: Krium/WORDPAD
        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);
            }
        }
コード例 #4
0
ファイル: RtdSaver.cs プロジェクト: Krium/WORDPAD
        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;
                RtdSaver.Save(doc);
            }
        }
コード例 #5
0
ファイル: RtfEditor.cs プロジェクト: Krium/WORDPAD
 public RtfEditor()
 {
     InitializeComponent();
     document              = new RichTextDocument();
     document.TextChanged += new EventHandler(document_TextChanged);
 }