如何找到 MDI 父窗体的内容区域?

发布于 2024-08-24 12:28:10 字数 141 浏览 1 评论 0原文

我想知道 MDI 父级中灰色可滚动区域的边界 - MDI 子级放置/排列的区域。我不希望它包含任何菜单、滚动条或状态区域——只是灰色区域。

this.mdiForm.ClientRectangle 给出了表单的整个内部,包括滚动条等,这不是我想要的。

I want to know the bounds of the grey scrollable area in an MDI parent -- the area in which MDI children are placed/arranged. I don't want it to include any menu, scroll bars, or status areas -- just the grey area.

this.mdiForm.ClientRectangle gives the whole interior of the Form, including scroll bars et al, which is not what I want.

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

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

发布评论

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

评论(2

风情万种。 2024-08-31 12:28:10

该控件名为 MdiClient,它会自动当 IsMdiContainer 属性设置为 true 时添加。您应该能够通过执行以下操作来访问它:

// traditional way
MdiClient client = null;
foreach (Control c in this.mdiForm.Controls) {
    client = c as MdiClient;
    if (client != null) {
        break;
    }
}

// linq
MdiClient client = this.mdiForm.Controls
                       .OfType<MdiClient>()
                       .FirstOrDefault();

The control is called MdiClient and it's automatically added when the IsMdiContainer property is set to true. You should be able to access it by doing:

// traditional way
MdiClient client = null;
foreach (Control c in this.mdiForm.Controls) {
    client = c as MdiClient;
    if (client != null) {
        break;
    }
}

// linq
MdiClient client = this.mdiForm.Controls
                       .OfType<MdiClient>()
                       .FirstOrDefault();
初懵 2024-08-31 12:28:10

一如既往,在发帖后,我就明白了。

Form 有一个内部属性MdiClient。因此,您可以得到这样的矩形:

PropertyInfo pi = typeof(Form).GetProperty("MdiClient", 
    BindingFlags.Instance | BindingFlags.NonPublic);
MdiClient mdiClient = (MdiClient)pi.GetValue(this.form1, null);
Rectangle scrollableRect = mdiClient.ClientRectangle;

当然,生产版本会在适当的位置检查 null 。

As always, just after posting, I figure it out.

Form has an internal property MdiClient. So, you can get the rectangle like this:

PropertyInfo pi = typeof(Form).GetProperty("MdiClient", 
    BindingFlags.Instance | BindingFlags.NonPublic);
MdiClient mdiClient = (MdiClient)pi.GetValue(this.form1, null);
Rectangle scrollableRect = mdiClient.ClientRectangle;

A production version would, of course, check for null in the appropriate places.

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