对于每个曾经问过自己"如何在不阻挡任务栏的情况下在多屏幕设置中最大化窗口"的人来说,这是一个帖子.
问题似乎是将MaximizeBox和MinimizeBox设置为false并且在多屏幕环境中以编程方式最大化的窗口覆盖整个屏幕,而不仅仅是Screen.WorkingArea.
要最大化窗口到工作区域,需要使用MaximizeBox和MinimizeBox属性,如下所示:
// This code should be placed in the Form's ResizeEnd handler
MaximizeBox = MinimizeBox = true; // Enable both boxes
WindowState = FormWindowState.Maximized; // Set to maximized
MaximizeBox = MinimizeBox = false; // Disable both boxes again
Run Code Online (Sandbox Code Playgroud)
因此,窗口将在屏幕上很好地最大化并且尊重屏幕的工作区域(不阻挡任务栏).