Hi...
I am trying to save a file in the MDI - which uses the RichTextBox... But I am not able to save the formatting to the text..
Example : - If I chnage the font, color, size of the text.. it doesnt save the formatting but stores the simple text..
NOTE: this is happening when I select the RTF option in the Save File Dialog box
public
void save_file()
{
savedlg.Filter =
"Text Documents (*.txt)|*.txt|Rich Text Documents (*.rtf)|*.rtf";
DialogResult res = savedlg.ShowDialog();
RichTextBox t1 = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (res == DialogResult.OK)
{
FileStream f1 = new FileStream(savedlg.FileName, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(f1);
char[] ary = t1.Text.ToCharArray();
int i = 0;
while (i <= ary.Length - 1)
{
sw.Write(ary[i++]);
}
sw.Close();
f1.Close();
fileName = savedlg.FileName;
tabControl1.SelectedTab.Text = System.IO.
Path.GetFileName(fileName);
fileName =
"";
}
else if (res == DialogResult.Cancel)
return;
else
{
t1.SaveFile(fileName,
RichTextBoxStreamType.RichText);
tabControl1.SelectedTab.Text = System.IO.
Path.GetFileName(fileName);
}
}
Please Help me...!!!