简体   繁体   English

设置ClassLibrary c#中存在的Windows窗体的所有者

[英]set owner of Windows Form that exist in ClassLibrary c#

I have ClassLibrary that have a Windows Form named LookUpBox . 我有ClassLibrary,它具有一个名为LookUpBoxWindows Form I want to Call LookUpBox from my application and set my application as owner of that and do it as blow: 我想从我的应用程序中调用LookUpBox我的应用程序设置LookUpBox应用程序的所有者,并将其作为打击:

LookUpBox foo = new LookUpBox();
foo.Owner = this;
foo.ShowDialog();

But when Run my application and press Alt + Enter I see 2 form like : 但是,当运行我的应用程序并按Alt + Enter时,我看到2形式,如:

Alt_Enter窗口

I excepted with set of Owner of the foo , I see single Window with Alt + Enter . 除了fooOwner之外,我看到了一个带有Alt + Enter的 Window。 Anybody know how to solve this problem? 有人知道如何解决这个问题吗? Thanks in advance 提前致谢

Window.Owner states: Window.Owner状态:

When you open a child window by calling ShowDialog, you should also set the Owner property of the child window. 当通过调用ShowDialog打开子窗口时,还应该设置子窗口的Owner属性。 If you don't, then your users won't be able to restore both child window and parent window by pressing the task bar button. 如果您不这样做,则您的用户将无法通过按任务栏按钮来还原子窗口和父窗口。 Instead, pressing the task bar button will yield a list of windows, including both child and parent window, for them to select; 相反,按下任务栏按钮将产生一个窗口列表,包括子窗口和父窗口,供他们选择; only the selected window is restored. 仅还原所选窗口。

Form.Owner states: Form.Owner声明:

When a form is owned by another form, it is closed or hidden with the owner form. 当一个表单由另一个表单拥有时,它将被所有者表单关闭或隐藏。 For example, consider a form named Form2 that is owned by a form named Form1. 例如,考虑一个名为Form2的表单,该表单由一个名为Form1的表单拥有。 If Form1 is closed or minimized, Form2 is also closed or hidden.Owned forms are also never displayed behind their owner form. 如果关闭或最小化了Form1,则Form2也将关闭或隐藏。拥有的窗体也永远不会显示在其所有者窗体的后面。 You can use owned forms for windows such as find and replace windows, which should not disappear when the owner form is selected. 您可以对窗口使用拥有的表单,例如查找和替换窗口,当选择所有者表单时,它们不应消失。 To determine the forms that are owned by a parent form, use the OwnedForms property. 若要确定由父窗体拥有的窗体,请使用OwnedForms属性。

So what you need to do is to explicitly set foo.ShowInTaskbar = False to keep it hidden from taskbar 因此,您需要做的是显式设置foo.ShowInTaskbar = False使其隐藏在任务栏中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM