我的 MDI 客户端区域的真实大小 - 高度 - 14?
我试图将 MDI 子窗口置于父窗口客户区的中心。通过反复试验,我发现以下方法可以工作:
((parent.ClientSize.Width - 4)-centerchild.Width)/2, ((parent.ClientSize.Height - 14)-centerchild.Height)/2
我想我从宽度中减去的 4 是两侧边框的大小,我可以通过在父级中获取 MDIClient 控件(感谢堆栈溢出来发现这一点)或通过减去来获得该数字SystemInformation.Border3DSize.Width * 2。这对我来说很有意义。
我很难弄清楚为什么我需要从高度中减去 14。假设底部边框是 2,那么仍然剩下 12,我无法与任何内容相协调。 (如果上边框也为 2,那么仍然会留下 10 无法解释。)我研究了以下内容:
- 在父级中获取 MDIClient 控件并不能获得确切的高度,因为它可以获得宽度。相反,它让我得到parent.ClientSize.Height - 28,这是我通过反复试验得出的差异的两倍。 28 可能代表底部边框 (2) + 顶部边框 (2) + 菜单条的高度 (24),但这并不能解释我发现的完美的 14。
- 菜单条高度 - 正如我上面所说,是 24。
- SystemInformation 中的各种其他窗口元素度量。也许我忽略了一个,但似乎没有什么可以向我解释。
我当然可以使用带有我的试验和错误编号的代码,但我讨厌不理解。有谁有任何想法可以解释 14 的(总)身高差吗?
I am trying to center an MDI Child window in the center of my parent window's client area. By trial and error, I had found the following to work:
((parent.ClientSize.Width - 4)-centerchild.Width)/2, ((parent.ClientSize.Height - 14)-centerchild.Height)/2
I figured the 4 that I subtract from the width is the size of the border on either side, and I am able to get that number by either getting the MDIClient control within the parent (thanks to stack overflow for my finding that), or by subtracting SystemInformation.Border3DSize.Width * 2. This makes sense to me.
I am having a much harder time figuring out why I need to subtract 14 from the height. Assuming the bottom border is 2, that still leaves a number of 12 which I cannot reconcile with anything. (If there's also a top border of 2, then t hat still leaves 10 unexplained.) I have looked into the following:
- Getting the MDIClient control within the parent does not get me that exact height as it does the width. Rather, it gets me parent.ClientSize.Height - 28, which is double the difference I worked out by trial and error. 28 might represent a bottom border (2) + a top border (2) + the height of the menu strip (24), but that does not explain the 14 that I have found to be perfect.
- The Menu Strip height - as I said above, that's 24.
- Various other window-element measures in SystemInformation. Perhaps I overlooked one, but nothing seems to explain it to me.
I could certainly use the code with my trial and error numbers, but I hate to not understand. Does anyone have any ideas that would explain the (total) height difference of 14?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎没有一个框架函数能够为 MDIClient 提供正确的尺寸,API 函数(如 GetWindowRect 或 GetWindowInfo)也不会。从 NativeWindow 派生,子类化 MDIClient 窗口,并在遇到 wparam==true 时查看 WM_NCCALCSIZE,在这种情况下,lparam 指向将具有正确值的 NCCALCSIZE_PARAM 结构。
It seems none of the framework functions will give the correct dimensions for the MDIClient, nor will API functions like GetWindowRect or GetWindowInfo. Derive from NativeWindow to subclass the MDIClient window and peek at WM_NCCALCSIZE when it comes across with wparam==true in which case lparam points to a NCCALCSIZE_PARAM struct that will have the right values.