保留双显示器的表单位置和大小

发布于 2024-10-13 18:31:31 字数 162 浏览 6 评论 0原文

我有代码在关闭时保留表单的大小和位置,并在加载时定位表单并调整其大小。

我想考虑到加载时持久位置可能超出屏幕范围。在单个显示器设置中很容易进行测试,但对于多个显示器,我该如何测试。我不知道屏幕是水平设置还是垂直设置等。不知何故,我需要确定所有屏幕的组合区域,并查明表单的持久位置是否在该区域内。

I have code that persists a forms size and location when it closes, and positions and sizes the form when it loads.

I want to take into account that on load it is possible that the persisted location is outside of the bounds of the screen. Easy to test in a single monitor setup but for multiple monitors, how can I test that. I don't know if the screens are set up horizontally or vertically etc. Somehow I need to determine the combined area of all screens and find out if the forms persisted location is within that area.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2024-10-20 18:31:31

用于记住和恢复窗口状态的一对好函数是 GetWindowPlacement< /code>SetWindowPlacementGetWindowPlacement 不仅检索普通窗口的当前状态和位置,而且对于最大化窗口,还检索其最大化之前的位置。

出于您的目的,SetWindowPlacement 非常有用,因为如果要求将窗口恢复到屏幕外,它知道将窗口微移到最近的屏幕上:

如果WINDOWPLACMENT中指定的信息会导致窗口完全脱离屏幕,系统将自动调整坐标以使窗口可见,同时考虑屏幕分辨率和多显示器配置。

不幸的是,我不知道这两个函数的现成 .NET 等效项,尽管它们可以通过 P/Invoke 直接调用(参见 http://pinvoke.net)。

A good pair of functions to use for remembering and restoring window state is GetWindowPlacement and SetWindowPlacement. GetWindowPlacement retrieves not only the current state and position of a normal window, but, for a maximised window, its location before it was maximised.

For your purposes, SetWindowPlacement is useful because knows to nudge a window onto the nearest screen if it's asked to restore it off screen:

If the information specified in WINDOWPLACEMENT would result in a window that is completely off the screen, the system will automatically adjust the coordinates so that the window is visible, taking into account changes in screen resolution and multiple monitor configuration.

Unfortunately I don't know of a ready-made .NET equivalent of these two functions, although they're straightforward to call via P/Invoke (cf http://pinvoke.net).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文