HeadBar.cs 2.4 KB

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