dimanche 22 novembre 2015

How to close program after button_click event

I have program in Winfroms. I use a lot of check boxes to pick my options. And there is main button1 to click after options choosing. Everything works, I click on it, everything is generated right, but my winforms window still stays and don't go away. I need to click on exit mark. Is it possible to run and exit program after button1 click? My code of button click event:

private void button1_Click(object sender, EventArgs e)
        {
        var header = File.ReadAllText(@"dir/header");
            var footer = File.ReadAllText(@"dir/footer");
            var sb = new StringBuilder();
            sb.AppendLine(header);
            if (checkBox1.CheckState == CheckState.Checked) sb.AppendLine(@"\include{chap2}");
            if (checkBox2.CheckState == CheckState.Checked) sb.AppendLine(@"\include{chap3}");
 sb.AppendLine(footer);
            File.WriteAllText(@"dir/final", sb.ToString());

I found tutorials about this problem, but there always was the same problem. You need to click exit mark and only then you can get out of winform window. Any ideas?

Thanks.




Aucun commentaire:

Enregistrer un commentaire