How to fully launch the WinForm interface upon activation

I have two dialogs: FormA and FormB . I use the following code to show (non-modal) FormB . Code is a click on a button made from FormA .

  private void button_Click(object sender, EventArgs e) { FormB fB = new FormB(); fB.Show(this); // FormA is the owner of FormB } 

The problem is that when FormB above FormA on the screen, if I click FormA , it is activated but not brought to the fore. In fact, FormB is always above FormA

Forms

Do you know why and how to change this behavior without removing the owner property?

NOTE. This is a simplification of my problem. In the real issue, FormA is the Windows Explorer window, and FormB is the managed WinForm, but the behavior is the same. If I do not pass IWin32Window to Show() , it works fine, but if I close A, B does not close and does not respond to events (see. The following entry).

0
source share
3 answers

You cannot do this without removing the owner property.

From the documentation: Own forms are also not displayed behind their owner form.

Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx

For your specific problem, why don't you listen to the Close Event and then explicitly close your own form?

+2
source

You can set the TopMost property to true.

0
source

For hacking, WindowState = FormWindowState.Minimized must be set in the OnDeactivate method of formB (or return it).

  protected override void OnDeactivate(EventArgs e) { base.OnDeactivate(e); this.WindowState = FormWindowState.Minimized; } 

I don’t know what you would like.

0
source

Source: https://habr.com/ru/post/894666/


All Articles