0

I am currently opening a folder for the user using Process.Start("C:\\Some\\Path").

Because of the calling form's TopMost property being set to true, the new window shows up behind that form and remains behind that form even if the user interacts with the new window.

How can this new window be defined so that its TopMost property is set to true? Otherwise, is there another way to put this window on top?

I've gone through many different properties of Process, looking for something that can set TopMost to true, or some other property that might have the same effect.

I could not find any options that work with explorer in command line that can force the window to be on top, that can be used as a parameter.

Sal
  • 11
  • 1
  • Feedback about how to improve the question would be more helpful than an anonymous downvote. – Sal Jun 25 '19 at 18:47
  • You should take a look at https://stackoverflow.com/a/13112158/3445247 – Mustafa Gursel Jun 25 '19 at 18:55
  • You shouldn't be using `TopMost` in your application. – NetMage Jun 25 '19 at 19:05
  • @NetMage because? – Sal Jun 25 '19 at 19:08
  • Because (I believe - the web is somewhat contradictory) setting `TopMost` on a form will make the window a topmost window across all applications, which except in _very_ special cases (e.g. Task Manager) is not how a polite application (for the end user) should behave. As someone else once wrote, I would uninstall the program and delete any references to it. – NetMage Jun 25 '19 at 20:40
  • @NetMage You make a good point. Thanks for the advice. This problem has been solved by considering this idea and approaching the problem from a different angle. Not sure if this ticket should remain. – Sal Jun 26 '19 at 17:06
  • @Sal you can always post your own answer to your question to help others in the future... – NetMage Jun 26 '19 at 17:15

1 Answers1

0

As was suggested in a comment, the best approach was to avoid the use of the TopMost property altogether.

An alternate way to ensure that dialogs appear on top of main (or parent) forms is to identify the parent form to the child form. This can be done by using the this keyword inside the ShowDialog() method call.

In C#:

someForm.ShowDialog(this)

In Visual Basic:

someForm.ShowDialog(me)

This will identify this form as the parent of the new dialog which will cause the new form to appear on top more reliably than not using this in the method call, without the use of the TopMost property, which can lead to other unintended problems.

This solves the issue identified in this ticket where windows unrelated to the current program appear behind dialogs created in the program.

Sal
  • 11
  • 1