Set owner of windows forms that exist in C # ClassLibrary

I have a ClassLibrary Windows Form

named LookUpBox

. I want to call LookUpBox

from my app and set my app as the owner of this and do it like a blow:

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

      

But when run my application and click Alt+ Enter, I see 2 form like:

Alt_Enter Window

I am excluded with the set Owner

for foo

, I see one window with Alt+ Enter. Does anyone know how to fix this problem? thanks in advance

+3


source to share


1 answer


Window.Owner :

When you open a child window by calling ShowDialog, you must also set the Owner property of the child window. If you don't, your users won't be able to restore the child window and parent window by clicking the taskbar button. Instead, clicking the taskbar button will give you a list of windows, including both child and parent windows, to select from; only the selected window is restored.

Form.Owner :



If the form is owned by another form, it is closed or hidden with the owner's form. For example, consider a form named Form2 that belongs to a form named Form1. If Form1 is closed or minimized, Form2 is also closed or hidden. Native forms are also not displayed behind their owner form. You can use owned forms for windows, such as find and replace windows, which shouldn't disappear when you select the owner shape. Use the OwnedForms property to identify the forms that are owned by the parent form.

So, you need to explicitly set foo.ShowInTaskbar = False

it to hide from the taskbar

+3


source







All Articles