| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using UAS_MES.PublicMethod;
- namespace UAS_MES.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 (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());
- }
- private void MinWindow_Click(object sender, EventArgs e)
- {
- this.FindForm().WindowState = FormWindowState.Minimized;
- }
- }
- }
|