1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace UAS_LabelMachine.CustomControl
- {
- public partial class HeadBar : UserControl
- {
- //需要关闭前提示窗口的在这里加
- private List<string> NeedConfirm = new List<string>() {"Main"};
- [DllImport("user32.dll")]
- public static extern bool ReleaseCapture();
- [DllImport("user32.dll")]
- public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
- public const int WM_SYSCOMMAND = 0x0112;
- public const int SC_MOVE = 0xF010;
- public const int HTCAPTION = 0x0002;
- //定义委托
- public delegate void OnHeadBarClick(object sender, EventArgs e);
- //定义事件
- public event OnHeadBarClick HeadBarDoubleClick;
- public HeadBar()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 用于对窗体的关闭,判断主窗体的时候退出程序,非主窗体时关闭该窗体,同时回收内存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void CloseWindow_Click(object sender, EventArgs e)
- {
- if (this.ParentForm.WindowState == FormWindowState.Normal || this.ParentForm.WindowState == FormWindowState.Maximized)
- {
- this.ParentForm.WindowState = FormWindowState.Minimized;
- }
- }
- /// <summary>
- /// 最小化父级窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MinWindow_Click(object sender, EventArgs e)
- {
- //判断是否需要关闭前的提示
- if (NeedConfirm.Contains(this.FindForm().Name))
- {
- string logout_confirm = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (logout_confirm == "Yes")
- {
- this.FindForm().Close();
- }
- }
- else {
- this.FindForm().Close();
- }
-
- }
- private void panel1_Click(object sender, EventArgs e)
- {
- HeadBarDoubleClick?.Invoke(sender, new EventArgs());
- }
- }
- }
|