开发者

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 chil开发者_开发百科dforms 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.


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 :)


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.


Hmm. I've created To forms. Then i set TopMost = true on both. The i add button to first and wrote new Form2().ShowDialog();

And all just fine. Form2 active and clickable. Form1 not since ShowDialog was called

And second variant works fine. Form2 opened in center of the screen.

May be i misunderstood something?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜