I want to display progress of saving a file using the "SaveFileDialog" and "Progress Bar" in a windows form. The file being saved is text file (rtf, txt, ...). This is what I use to save a file:
private void Save()
{
if (TabControl.TabPages.Count != 0)
{
SaveFileDialog.FileName = TabControl.SelectedTab.Name;
SaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //default path
SaveFileDialog.Filter = "Rich Text Format|*.rtf";//Extensions
SaveFileDialog.Title = "Save";
if (SaveFileDialog.ShowDialog() == DialogResult.OK)
{
if (SaveFileDialog.FileName.Length > 0)
{
GetCurrentDocument.SaveFile(SaveFileDialog.FileName, RichTextBoxStreamType.RichText);//Stream Type for .rtf
}
}
else if (SaveFileDialog.ShowDialog() == DialogResult.Cancel)
{
StatusBar.Text = "Saving Cancelled."; //Makes sure it doesn't crash on cancel
}
}
else
{
StatusBar.Text = "Can't save. No tabs are detected.";
}
}
The GetCurrentDocument is this:
private RichTextBox GetCurrentDocument
{
get
{
return
(RichTextBox)TabControl.SelectedTab.Controls["Body"];
}
}
Thus, SaveFile() is:
RichTextBox.SaveFile Method: Saves the contents of the RichTextBox to a file. msdn page
Somehow I want to display the saving on the progress bar, or at least display a notice when the saving is finished (when the file is in the final location).