Parentform和Owner之间有什么区别 [英] Whats the difference between Parentform and Owner

查看:61
本文介绍了Parentform和Owner之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在winforms中,我们有objForm.Owner和objForm.Parent.这两者之间有什么区别.

In winforms we have objForm.Owner and objForm.Parent. Whats the difference between these two.

我从窗体A打开了窗体B作为对话框,希望使用ParentForm属性从窗体B访问窗体A的公共属性,但最终由于ParentForm为null而最终使用Owner属性!

I opened a form B from form A as a dialog and was expecting to access form A's public properties from form B using ParentForm property but finally ended up using Owner property instead as ParentForm was null !!

推荐答案

当子窗口被嵌入在父窗口中并且不能移出其边界时,窗口之间存在父子关系.示例是诸如TextBox和Panel之类的子控件.而MDI窗口模型,MDI子窗口则嵌入在MDI父窗口中,并以深灰色MDI客户端窗口作为父窗口.

A parent-child relationship exists between windows when the child is embedded in the parent window and cannot move outside of its bounds. Examples are child controls like TextBox and Panel. And the MDI windowing model, MDI child windows are embedded in the MDI parent and parented to the dark-gray MDI client window.

自有窗口适用于顶层窗口,主要控制其Z顺序.拥有的窗口始终位于其所有者的顶部.它还被最小化并与其所有者一起恢复.例如工具窗口和对话框.

An owned window applies to top-level windows and primarily controls their Z-order. An owned window is always on top of its owner. It is also minimized and restored along with its owner. Examples are tool windows and dialogs.

请注意,窗体通常是顶级窗口,并且没有父窗口.因此,将不会对其Parent和ParentForm属性使用.但是,可以通过将其TopLevel属性设置为 false 将其转换为子窗口.示例代码在此处.

Note how a Form is normally a top-level window and does not have a parent. So wouldn't have a use for its Parent and ParentForm properties. It can however be turned into a child window by setting its TopLevel property to false. Sample code is here.

这篇关于Parentform和Owner之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆