HeadBar.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using System.Windows.Forms;
  6. using UAS_MES.PublicMethod;
  7. namespace UAS_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. //定义委托
  21. public delegate void OnHeadBarClick(object sender, EventArgs e);
  22. //定义事件
  23. public event OnHeadBarClick HeadBarDoubleClick;
  24. public HeadBar()
  25. {
  26. InitializeComponent();
  27. }
  28. /// <summary>
  29. /// 用于对窗体的关闭,判断主窗体的时候退出程序,非主窗体时关闭该窗体,同时回收内存
  30. /// </summary>
  31. /// <param name="sender"></param>
  32. /// <param name="e"></param>
  33. public void CloseWindow_Click(object sender, EventArgs e)
  34. {
  35. //判断是否需要关闭前的提示
  36. if (NeedConfirm.Contains(this.FindForm().Name))
  37. {
  38. string logout_confirm = MessageBox.Show(this.ParentForm, "是否退出程序", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  39. if (logout_confirm == "Yes")
  40. {
  41. this.FindForm().Close();
  42. }
  43. }
  44. else
  45. {
  46. this.FindForm().Close();
  47. }
  48. }
  49. private void panel1_Click(object sender, EventArgs e)
  50. {
  51. HeadBarDoubleClick?.Invoke(sender, new EventArgs());
  52. }
  53. private void MinWindow_Click(object sender, EventArgs e)
  54. {
  55. this.FindForm().WindowState = FormWindowState.Minimized;
  56. }
  57. }
  58. }