Advertisement
DrAungWinHtut

openfiledialog.cs

Nov 11th, 2022
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System.IO;
  2.  
  3. namespace TextEditor01
  4. {
  5.     public partial class frmEditor : Form
  6.     {
  7.         public frmEditor()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.  
  12.         private void btnSave_Click(object sender, EventArgs e)
  13.         {
  14.             string sText = txtEditor.Text;
  15.             string sFname = "";
  16.  
  17.             if(saveFileDialog1 .ShowDialog ()==DialogResult.OK)
  18.             {
  19.                 sFname = saveFileDialog1.FileName;
  20.  
  21.                 StreamWriter sw = new StreamWriter(sFname, true);
  22.                 sw.WriteLine(sText);
  23.                 sw.Close();
  24.                 MessageBox.Show("File is Saved!");
  25.             }
  26.             else
  27.             {
  28.                 MessageBox.Show("File saving cancel!");
  29.             }
  30.            
  31.            
  32.         }
  33.  
  34.         private void btnClear_Click(object sender, EventArgs e)
  35.         {
  36.             txtEditor .Clear();
  37.            
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement