CloseForm.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace WinBox
  13. {
  14. public partial class CloseForm : Form
  15. {
  16. private MainForm mainForm = null;
  17. public CloseForm()
  18. {
  19. InitializeComponent();
  20. }
  21. public CloseForm(MainForm mainForm)
  22. {
  23. this.mainForm = mainForm;
  24. InitializeComponent();
  25. }
  26. private void CloseForm_Load(object sender, EventArgs e)
  27. {
  28. Rectangle rect = Screen.GetWorkingArea(this);
  29. this.Height = rect.Height;
  30. this.Width = rect.Width;
  31. this.Location = new Point(0, 0);
  32. //this.Owner.Hide();
  33. }
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. this.mainForm.Show();
  37. }
  38. private void button2_Click(object sender, EventArgs e)
  39. {
  40. MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
  41. DialogResult dr = MessageBox.Show("如果有下载课程操作会被终止,确认要退出吗", "退出",messButton);
  42. if (dr == DialogResult.OK)//如果点击“确定”按钮
  43. {
  44. this.Close();
  45. try
  46. {
  47. RunBat("C:\\Lingjiao\\winBoxNode\\stop.bat");
  48. }
  49. catch (Exception ex)
  50. {
  51. }
  52. }
  53. }
  54. private void RunBat(string batPath)
  55. {
  56. Process pro = new Process();
  57. FileInfo file = new FileInfo(batPath);
  58. pro.StartInfo.WorkingDirectory = file.Directory.FullName;
  59. pro.StartInfo.FileName = batPath;
  60. pro.StartInfo.CreateNoWindow = false;
  61. pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  62. pro.Start();
  63. pro.Close();
  64. }
  65. private void CloseForm_FormClosing(object sender, FormClosingEventArgs e)
  66. {
  67. }
  68. private void CloseForm_FormClosed(object sender, FormClosedEventArgs e)
  69. {
  70. try
  71. {
  72. RunBat("C:\\Lingjiao\\winBoxNode\\stop.bat");
  73. }
  74. catch (Exception ex)
  75. {
  76. }
  77. }
  78. }
  79. }