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

set owner of Windows Form that exist in ClassLibrary c#

我的 ClassLibrary 有一个名为 LookUpBoxWindows Form。我想从我的应用程序中调用 LookUpBox 并将我的应用程序设置为该应用程序的所有者,然后按以下方式进行操作:

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

但是当 运行 我的应用程序并按 Alt+Enter 我看到 2 种形式,如:

我用 fooOwner 组除外,我用 Alt+Enter 看到单个 Window 。有人知道如何解决这个问题吗?提前致谢

Window.Owner 状态:

When you open a child window by calling ShowDialog, you should also set the Owner property of the child window. 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 状态:

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. If Form1 is closed or minimized, Form2 is also closed or hidden.Owned forms are also never displayed behind their owner form. 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.

所以你需要做的是显式设置foo.ShowInTaskbar = False使其在任务栏中隐藏