| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using 优软MES.PublicMethod;
- namespace 优软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 HeadBar()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 用于对窗体的关闭,判断主窗体的时候退出程序,非主窗体时关闭该窗体,同时回收内存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void CloseWindow_Click(object sender, EventArgs e)
- {
- //判断是否需要关闭前的提示
- if (NeedConfirm.Contains(this.ParentForm.Name))
- {
- MessageBoxButtons messButton = MessageBoxButtons.YesNo;
- string logout_confirm = MessageBox.Show(this.ParentForm, "是否关闭", "提示", messButton).ToString();
- if (logout_confirm == "Yes")
- {
- this.ParentForm.Close();
- }
- }
- else {
- this.ParentForm.Close();
- }
- }
- /// <summary>
- /// 最小化父级窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MinWindow_Click(object sender, EventArgs e)
- {
- if (this.ParentForm.WindowState == FormWindowState.Normal) {
- this.ParentForm.WindowState = FormWindowState.Minimized;
- }
- }
-
- }
- }
|