Reputation: 14777
There are a lot of questions around about this for WinForms but I haven't seen one that mentions the following scenario.
I have three forms:
(X) Main
(Y) Basket for drag and drop that needs to be on top
(Z) Some other dialog form
X is the main form running the message loop.
X holds a reference to Y and calls it's Show() method on load.
X then calls Z.ShowDialog(Z).
Now Y is no longer accessible until Z is closed.
I can somewhat understand why (not really). Is there a way to keep Y floating since the end user needs to interact with it independently of any other application forms.
Upvotes: 1
Views: 6825
Reputation: 125197
If you want to show a window using ShowDialog
but you don't want it block other windows other than main form, you can open other windows in separate threads. For example:
private void ShowY_Click(object sender, EventArgs e)
{
//It doesn't block any form in main UI thread
//If you also need it to be always on top, set y.TopMost=true;
Task.Run(() =>
{
var y = new YForm();
y.TopMost = true;
y.ShowDialog();
});
}
private void ShowZ_Click(object sender, EventArgs e)
{
//It only blocks the forms of main UI thread
var z = new ZForm();
z.ShowDialog();
}
Upvotes: 4
Reputation: 333
You can change your main form (X) to be an MDI container form (IsMdiContainer = true). Then you can add the remaining forms as child forms to X. Then use the Show method instead of ShowDialog to load them. This way all child forms will float within the container.
You can add the child forms to X like this:
ChildForm Y = new ChildForm();
Y.MdiParent = this //X is the parent form
Y.Show();
Upvotes: 0
Reputation: 57
In x, you can put a y.TopMost = true; after Z.ShowDialog(). This will put y on the top. Then, if you want other forms to work, you can put a y.TopMost = false; right after the y.TopMost = true; This will put the window on top, but allow other forms to go over it later.
Or, if the issue is one form being put on top of the other, then you can change the start position of one of the forms in the form's properties.
Upvotes: 0