HeadBar.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using System.Windows.Forms;
  6. using 优软MES.PublicMethod;
  7. namespace 优软MES.CustomControl
  8. {
  9. public partial class HeadBar : UserControl
  10. {
  11. //需要关闭前提示窗口的在这里加
  12. private List<string> NeedConfirm = new List<string>() {"Main"};
  13. [DllImport("user32.dll")]
  14. public static extern bool ReleaseCapture();
  15. [DllImport("user32.dll")]
  16. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  17. public const int WM_SYSCOMMAND = 0x0112;
  18. public const int SC_MOVE = 0xF010;
  19. public const int HTCAPTION = 0x0002;
  20. public HeadBar()
  21. {
  22. InitializeComponent();
  23. }
  24. /// <summary>
  25. /// 用于对窗体的关闭,判断主窗体的时候退出程序,非主窗体时关闭该窗体,同时回收内存
  26. /// </summary>
  27. /// <param name="sender"></param>
  28. /// <param name="e"></param>
  29. public void CloseWindow_Click(object sender, EventArgs e)
  30. {
  31. //判断是否需要关闭前的提示
  32. if (NeedConfirm.Contains(this.ParentForm.Name))
  33. {
  34. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  35. string logout_confirm = MessageBox.Show(this.ParentForm, "是否关闭", "提示", messButton).ToString();
  36. if (logout_confirm == "Yes")
  37. {
  38. this.ParentForm.Close();
  39. }
  40. }
  41. else {
  42. this.ParentForm.Close();
  43. }
  44. }
  45. /// <summary>
  46. /// 最小化父级窗体
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. private void MinWindow_Click(object sender, EventArgs e)
  51. {
  52. if (this.ParentForm.WindowState == FormWindowState.Normal) {
  53. this.ParentForm.WindowState = FormWindowState.Minimized;
  54. }
  55. }
  56. }
  57. }