Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. private void SalvarClick(object sender, EventArgs e)
  2. {
  3.  
  4. SaveFileDialog sfd = new SaveFileDialog();
  5. sfd.Filter = "Arquivo texto | *.txt";
  6. sfd.ShowDialog();
  7.  
  8. if(string.IsNullOrEmpty(sfd.FileName) == false)
  9. {
  10. try
  11. {
  12. using (StreamWriter writer = new StreamWriter(sfd.FileName, false, Encoding.UTF8))
  13. {
  14. writer.Write(JanelaDeTxt.Text);
  15. writer.Flush();
  16. //Application.Exit();
  17. this.Close();
  18. }
  19. }
  20. catch(Exception ex)
  21. {
  22. MessageBox.Show(string.Format("Não foi possível salvar o arquivo. Erro: [0]", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
  23. }
  24.  
  25. }
  26.  
  27. }
  28.  
  29. private void sairToolStripMenuItem_Click(object sender, EventArgs e)
  30. {
  31.  
  32. if (!string.IsNullOrEmpty(this.JanelaDeTxt.Text))
  33. {
  34. DialogResult result = MessageBox.Show("Deseja salvar arquivo?", "Sair do programa", MessageBoxButtons.YesNoCancel);
  35. if (result == DialogResult.Yes)
  36. {
  37. SalvarClick(sender, e);
  38. }
  39. else if(result == DialogResult.No)
  40. {
  41. Application.Exit();
  42. }
  43. }
  44. else
  45. {
  46. Application.Exit();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement