RichTextBox rtb = tabControl1.SelectedTab.Controls[0] as RichTextBox;
//StreamWriter sr = new StreamWriter(openFileDialog1.FileName, false, Encoding.UTF8);
if (tabControl1.SelectedTab.Text != "new " + tabControl1.SelectedIndex)
{
saveFileDialog1.FileName = GetFileName(tabControl1.SelectedTab.Text);
}
if (tabControl1.TabPages.Count == 0)
{
newTab();
}
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (!File.Exists(saveFileDialog1.FileName))
{
rtb.SaveFile(GetFileName(saveFileDialog1.FileName), RichTextBoxStreamType.PlainText);
tabControl1.SelectedTab.Text = GetFileName(saveFileDialog1.FileName);
}
else
{
File.Delete(saveFileDialog1.FileName);
rtb.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
tabControl1.SelectedTab.Text = GetFileName(saveFileDialog1.FileName);
}
}