Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void SalvarClick(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Arquivo texto | *.txt";
- sfd.ShowDialog();
- if(string.IsNullOrEmpty(sfd.FileName) == false)
- {
- try
- {
- using (StreamWriter writer = new StreamWriter(sfd.FileName, false, Encoding.UTF8))
- {
- writer.Write(JanelaDeTxt.Text);
- writer.Flush();
- //Application.Exit();
- this.Close();
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(string.Format("Não foi possível salvar o arquivo. Erro: [0]", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void sairToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(this.JanelaDeTxt.Text))
- {
- DialogResult result = MessageBox.Show("Deseja salvar arquivo?", "Sair do programa", MessageBoxButtons.YesNoCancel);
- if (result == DialogResult.Yes)
- {
- SalvarClick(sender, e);
- }
- else if(result == DialogResult.No)
- {
- Application.Exit();
- }
- }
- else
- {
- Application.Exit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement