What are the differences among Top Level Window, Child window, Dialog(modal) window and non-dialog (modeless) windows?

安稳与你 提交于 2021-02-08 04:37:40

问题


Can any body please tell me how to distinguish among them?

I have difficulty in understanding what are the distinguishing factors for top level child windows vs dialog/non-dialog window? Can the top level window be dialog/non-dialog window? Can the child window be dialog/non-dialog window?


回答1:


Top-level forms are owned by the desktop, whereas child forms belong to another form; this means that closing or minimising the owning form will also affect the child form.

Modal forms/dialogs block the calling thread until the form is closed, whereas modeless forms allow you to interact with other forms in the application while shown. Any form can be modal/modeless, regardless of whether it is a top-level or child form - however the default behaviour for modal dialogs is to be owned by the form that caused them to be shown.




回答2:


From MSDN:

Modal

A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application.

Modeless

Modeless forms let you shift the focus between the form and another form without having to close the initial form.

A top-level window can be either modal (dialog) or modeless.

A top-level window is owned by the desktop, thus it cannot be a child of a parent form.

A child window, owned by a parent form, is not a top-level form, because it has a parent. But it can be on top in the Z order, and can be modal or modeless depending on how it is displayed, with either ShowDiaglog() or Show() respectively.




回答3:


Top Level Window: The windows which are not owned by any other windows and hence they govern their own lifetime. Example Notepad window

Child window: The windows which are owned by some other window. This other window itself could be Top-level or Child. Example Edit box or status bar of Notepad, so if you close Notepad window edit box, status bar etc windows are gone.

Modal window: The window which blocks current threads execution until it is alive. If it is a child window then any interaction with its parent window will be blocked. Example Font dialog box of Notepad, if you open Font window, you can not type anything on Notepad window.

Modeless windows: The window which doesnt block current thread's execution when it is alive so if it is a child window it allows you to interact with its parent. example Find dialog box of Notepad, if you press Ctrl+F and open Find window, then you can put it aside and continue typing on main Notepad window.

Important point, a window can either be Child or Top level but cannot be both.

Hope this helps.



来源:https://stackoverflow.com/questions/33139759/what-are-the-differences-among-top-level-window-child-window-dialogmodal-win

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!