Reputation: 11
I use showdialog for show modal windows, but i have a problem in some computers with windows XP or windows 7 the parent window show in front after show a second modal window. My program is in .NET 4. Any suggestion?
In my main window i have a button with the code:
private void btnBox_Click(object sender, EventArgs e)
{
frmBox fBox = new frmBox();
fBox.ShowDialog();
}
And my code in a button inner frmBox is:
private void btnSearch_Click(object sender, EventArgs e)
{
frmSearch fSearch = new frmSearch();
fSearch.ShowDialog();
}
Upvotes: 0
Views: 615
Reputation: 17001
Show the dialog using the ShowDialog
overload that takes another Form
as an argument. This will set the dialog's Owner
to that form. Owned forms are always displayed on top of their owner.
From MSDN:
When a form is owned by another form, it is closed or hidden with the owner form. For example, consider a form named Form2 that is owned by a form named Form1. If Form1 is closed or minimized, Form2 is also closed or hidden. Owned forms are also never displayed behind their owner form.
The following code is usually sufficient, but you may need to modify the argument depending on where you are opening the dialog from.
someForm.ShowDialog(this);
Upvotes: 1