简体   繁体   中英

Start Process as Top Window

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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