|
  
- Thread
- 86
- Credit
- 4
- Money
- 4
- Read Perm.
- 100
- From
- Cambodia
- Joined
- 11-3-2009

|
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. |
|