예제 #1
0
        //=------------------------------------------------------------------=
        // cmdFileOpen_Execute
        //=------------------------------------------------------------------=
        /// <summary>
        ///   The user has clicked on something attached to the Open Document
        ///   command (File.Open or a button on the toolbar).  Go and let them
        ///   open a document now.
        /// </summary>
        ///
        /// <param name="sender">
        ///   Where it comes from.
        /// </param>
        ///
        /// <param name="e">
        ///   EventArgs.Empty
        /// </param>
        ///
        private void cmdFileOpen_Execute(object sender, EventArgs e)
        {
            ResourceManager rm = UnifiedCommandsDemoMain.GetResourceManager();
            DialogResult    dr;

            this.openFileDialog1.AddExtension = true;
            this.openFileDialog1.DefaultExt   = "rtf";
            this.openFileDialog1.Filter       = rm.GetString("strOpenSaveFilter");
            this.openFileDialog1.Multiselect  = false;
            dr = this.openFileDialog1.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    FileInfo f = new FileInfo(this.openFileDialog1.FileName);
                    if (f.Extension == ".rtf")
                    {
                        this.richTextBox1.LoadFile(this.openFileDialog1.FileName);
                    }
                    else
                    {
                        this.richTextBox1.LoadFile(this.openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                    }
                    this.m_fileName = this.openFileDialog1.FileName;
                }

                catch (ArgumentException aee)
                {
                    MessageBox.Show("ArgumentException " + aee.Message.ToString());
                }
                catch (IOException ioe)
                {
                    MessageBox.Show("IOException " + ioe.Message.ToString());
                }
            }
        }
예제 #2
0
        //=------------------------------------------------------------------=
        // cmdFileSaveAs_Execute
        //=------------------------------------------------------------------=
        /// <summary>
        ///   The use has clicked on the File.Save As menu item, so go and
        ///   save the document now, letting them choose a filename.
        /// </summary>
        ///
        /// <param name="sender">
        ///   Where it comes from.
        /// </param>
        ///
        /// <param name="e">
        ///   EventArgs.Empty
        /// </param>
        ///
        private void cmdFileSaveAs_Execute(object sender, EventArgs e)
        {
            ResourceManager rm = UnifiedCommandsDemoMain.GetResourceManager();
            DialogResult    dr;

            this.saveFileDialog1.AddExtension    = true;
            this.saveFileDialog1.DefaultExt      = "rtf";
            this.saveFileDialog1.Filter          = rm.GetString("strOpenSaveFilter");
            this.saveFileDialog1.OverwritePrompt = true;
            dr = this.saveFileDialog1.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    this.richTextBox1.SaveFile(this.saveFileDialog1.FileName);
                    this.m_fileName = this.saveFileDialog1.FileName;
                }
                catch (IOException ioe)
                {
                    MessageBox.Show("IOException " + ioe.Message.ToString());
                }
            }
        }