Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a WPF and an enter button on it, when i click enter, a new WPF is opened. But it is behind first WPF, so i used this,

mw2.ShowDialog();
     mw2.BringWindowToTop();



or


C#
mw2.ShowDialog();
     mw2.BringToFront();


but VS says "does not contain the definition"

How can i Bring that window to front.


Thanks.
Posted
Comments
CHill60 6-Feb-13 10:28am    
does mw2.Activate work?
Hslldm 7-Feb-13 3:35am    
No but,mw2.Owner = this; solved!

To me the question is not "How do I bring it to the front" but why did it not come to the front automatically?

The only situation in which I have seen a dialog not come to the front was when the creating window was TopMost and the dialog's Owner property had not been set.

Setting the Owner should force the dialog to the front.

Alan.
 
Share this answer
 
Comments
Hslldm 6-Feb-13 10:55am    
How can i do that?
CHill60 6-Feb-13 11:08am    
mw2.Owner = this; will set the owner, but that didn't solve the problem when I tried it. mw2.TopMost = true; seems to work ... or you can remove the .TopMost = true on the first form
Hslldm 6-Feb-13 11:12am    
"does not contain a definition for TopMost " gives this error
Hslldm 6-Feb-13 11:36am    
mw2.Owner = this; solved! Thanks
CHill60 7-Feb-13 4:24am    
aha! Didn't work for me with Windows Forms in VS2005 but clearly does work with VS2012 and WPF ... just goes to show that Microsoft *do* fix things occasionally ;-p
mw2.Activate(); will attempt to bring the window to the front and focus on it.
 
Share this answer
 
Comments
Hslldm 6-Feb-13 10:50am    
I wrote like this but didnt work.

else
{
mw2.ShowDialog();
mw2.Activate();
}
}
}
Pete O'Hanlon 6-Feb-13 10:58am    
That's because you're creating a dialog. A dialog doesn't return to the calling code until it's closed, so it won't hit the Activate. I apologise because when I read your question, for some reason, I thought you'd called Show() and not ShowDialog().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900