How do I 'bring to front' a .NET windows form?

Hi,

I have an MFC application which is calling a C++ .NET windows form (in managed mode).  The form displays but it appears behind the calling MFC program.

How do I make this windows form appear in front of all other windows?  I have tried using newDlg->BringToFront() but this does not work.
#pragma managed
void EventingDlg::customiseToolbar()
{
	Form1 ^ newDlg = gcnew Form1();
	newDlg->ShowDialog();
	newDlg->BringToFront();
}

Open in new window

ConfusionerAsked:
Who is Participating?
 
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
Have you tried setting TopMost property on the form to be true?

http://msdn2.microsoft.com/en-us/library/system.windows.window.topmost.aspx
0
 
lucky_jamesCommented:
does the comtrol of execution comes to newDlg->BringToFront(); statement during the life time of the dialog?...... can you please confirm that.
0
 
ConfusionerAuthor Commented:
I'm not too sure what your asking here.  The form is definately been created, because it appears on the screen.

That should mean that BringToFront() is called as well, but it doesn't actually do anything
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
lucky_jamesCommented:
after showdialog() the next instruction is executed when the dialog closes.

try as :
#pragma managed
void EventingDlg::customiseToolbar()
{
        Form1 ^ newDlg = gcnew Form1();
        newDlg->BringToFront();
        newDlg->ShowDialog();
}

Open in new window

0
 
ConfusionerAuthor Commented:
OK tried that, it's still displaying behind my other window.

I also tried putting this line in form1:
this->BringToFront();

but didn't work either.
0
 
ConfusionerAuthor Commented:
evilrix,
Thanks! Exactly what I needed.
0
 
evilrixSenior Software Engineer (Avast)Commented:
Very welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.