欢迎光临
我的个人博客网站

WPF 禁用窗体最大最小按键

 /// <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);             };         } 

  

赞(0) 打赏
未经允许不得转载:张拓的天空 » WPF 禁用窗体最大最小按键
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

专业的IT技术经验分享 更专业 更方便

联系我们本站主机

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏