Back Forum Reply New

C# - RichTextPad v 0.1

This is a rich text file editor.

Functions in v 0.1
   .New:
   .Open
   .Save As

Code

private const string sTitle = "RichTextPad v 0.1"; // Application title

New
rtbPad.ResetText();
this.Text = sTitle;

Open
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Rich Text File (*.rtf) | *.rtf|Text File (*.txt) | *.txt|All Files (*.*) | *.*";
// Filter
dlg.CheckPathExists = true;
dlg.CheckFileExists = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
     this.Cursor = Cursors.WaitCursor;
     try

{

           RichTextBoxStreamType rtbType = new RichTextBoxStreamType();
           if (dlg.FileName.EndsWith(".txt"))
// Text file

rtbType =
RichTextBoxStreamType.PlainText;
           else

rtbType =
RichTextBoxStreamType.RichText;

rtbPad.LoadFile(dlg.FileName, rtbType);
// Load file
           this.Text = Path.GetFileName(dlg.FileName) + " - " + sTitle;

}

     catch (Exception ex)

{

           MessageBox.Show("Error while opening file.\n" + ex.Message, "Open", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

     finally

{

           this.Cursor = Cursors.Default;

}

}

Save As
SaveFileDialog dlg = new SaveFileDialog();
dlg.CheckPathExists =
true;
dlg.Filter =
"Rich Text File (*.rtf) | *.rtf|All Files (*.*) | *.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
         this.Cursor = Cursors.WaitCursor;
         try
         {
                      rtbPad.SaveFile(dlg.FileName);
                     this.Text = Path.GetFileName(dlg.FileName) + " - " + sTitle;
          }
          catch (Exception ex)
         {
                      MessageBox.Show("Error while saving file.\n" + ex.Message, "Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
        {
                     this.Cursor = Cursors.Default;
        }
}

Will add more functions into the up coming versions.
screen.jpg

RichTextPad.zip (19.82 KB)

ePrasart.
we have our programming professional in our forum, that is cool.
Back Forum