Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - How to deal with 2 "TopMost" Forms?

I have a parent form that is set to be TopMost and then I have another form that opens when a button is clicked. This child form is also set to be TopMost. The first issue I had was that when I opened the child form, the application would basically freeze because you couldn't access anything. I decided that instead of using ShowDialog() to open the child form, I would use Show(this). This did fix the initial problem but now I have a new one. The childforms start postition is set to be CenterParent and when I use Show(this), it doesn't work. Is there any way I can make the childform open while both it and the parent form are set to topmost while having the childforms start position set to CenterParent? Thank you.

like image 907
user Avatar asked Oct 26 '09 21:10

user


2 Answers

I've find something useful to share with you, guys. Instead following code

form2.TopMost = true;

use this code in main form:

form2.Owner = this;

If you use Form.TopMost property, the form will overlap all other non-topmost forms, but also those from other applications. Instead of this, set the Form.Owner property to the parent form – the one which should be under the form (e.g. the main form). G00d luck :)

like image 145
Shahryar Avatar answered Nov 01 '22 16:11

Shahryar


You could try clearing the TopMost property of the parent form for the duration that the child form is visible.

This would solve the problem of which form should be top most, as there will only ever be one.

like image 33
ChrisF Avatar answered Nov 01 '22 14:11

ChrisF