【问题标题】:How to Override Maximize Button in WPF?如何在 WPF 中覆盖最大化按钮?
【发布时间】:2018-08-28 02:04:59
【问题描述】:

我想覆盖 WPF 中窗口的最大化按钮以调整多于一台显示器的宽度和高度。 怎么做? 谢谢!

【问题讨论】:

  • 这是为您的应用程序还是其他人的应用程序?换句话说,你打算制作像 Ultramon 这样的东西吗?
  • 这是我的应用程序,现在我有双显示器了。
  • 但它只是捕获最大化事件,无法调整窗口的宽度、高度:)
  • 这就是为什么它不是答案而是评论。它应该让你更近一步

标签: c# wpf button overriding maximize


【解决方案1】:

检查这个:https://stackoverflow.com/a/52035623/9912441

您需要通过监视器信息找到所有监视器的总宽度和高度。

[DllImport("user32")]
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);

[DllImport("User32")]
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);

/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class MONITORINFO
{
     /// <summary>
     /// </summary>            
     public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));

     /// <summary>
     /// </summary>            
     public RECT rcMonitor = new RECT();

     /// <summary>
     /// </summary>            
     public RECT rcWork = new RECT();

     /// <summary>
     /// </summary>            
     public int dwFlags = 0;
}

void Maximize(HWND hWnd, HMONITOR hMonitor)
{
    // access monitor info
    MONITORINFO monitorInfo = { sizeof(MONITORINFO) };
    GetMonitorInfo(hMonitor, &monitorInfo);

    // restore window to normal size if it is not yet
    ShowWindow(hWnd, SW_RESTORE);

    // move window to the monitor
    SetWindowPos(hWnd, nullptr, monitorInfo.rcMonitor.left, 
    monitorInfo.rcMonitor.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);

    // maximize window
    ShowWindow(hWnd, SW_MAXIMIZE);    
}

【讨论】:

  • 你能给我一个小演示代码吗?只需按下最大化按钮并覆盖双显示器。谢谢!
  • @MickyD 是啊是啊,对不起!
猜你喜欢
  • 1970-01-01
  • 2010-09-23
  • 2011-01-06
  • 1970-01-01
  • 2014-10-14
  • 1970-01-01
  • 2021-07-15
  • 2017-01-07
  • 2011-05-24
相关资源
最近更新 更多