/// <summary>
    /// 禁用窗体最大最小按键
    /// </summary>
    internal static class WindowExtensions
    {
        [DllImport("user32.dll")]
        internal extern static int SetWindowLong(IntPtr hwnd, int index, int value);

        [DllImport("user32.dll")]
        internal extern static int GetWindowLong(IntPtr hwnd, int index);

        internal static void HideMinimizeAndMaximizeButtons(System.Windows.Window window)
        {
            const int GWL_STYLE = -16;

            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            long value = GetWindowLong(hwnd, GWL_STYLE);

            SetWindowLong(hwnd, GWL_STYLE, (int)(value & -131073 & -65537));

        }

        internal static void DisableMinimizeButton(System.Windows.Window window)
        {
            const int GWL_STYLE = -16;
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            long value = GetWindowLong(hwnd, GWL_STYLE);

            SetWindowLong(hwnd, GWL_STYLE, (int)(value & -131073));
        }

        internal static void DisableMaximizeButton(System.Windows.Window window)
        {
            const int GWL_STYLE = -16;
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            long value = GetWindowLong(hwnd, GWL_STYLE);

            SetWindowLong(hwnd, GWL_STYLE, (int)(value & -65537 & -131073));
        }
    }

  用法

 public Window2()
        {
            InitializeComponent();
            this.SourceInitialized += (x, y) =>
            {
                WindowExtensions.DisableMinimizeButton(this);
            };
        }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-08-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-10
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
相关资源
相似解决方案