diff --git a/OpenNest/Controls/DrawingLibraryView.cs b/OpenNest/Controls/DrawingLibraryView.cs
index 4498729f..cf0b8c82 100644
--- a/OpenNest/Controls/DrawingLibraryView.cs
+++ b/OpenNest/Controls/DrawingLibraryView.cs
@@ -100,6 +100,12 @@ namespace OpenNest.Controls
///
public bool QuantitiesChanged { get; private set; }
+ ///
+ /// The window that owns this view's dialogs. A dialog owned by a child control is not kept
+ /// above its top-level window, so it can fall behind it.
+ ///
+ private IWin32Window DialogOwner => (IWin32Window)TopLevelControl ?? this;
+
public DrawingLibraryView()
{
InitializeComponent();
@@ -126,24 +132,24 @@ namespace OpenNest.Controls
EditDrawing = edit =>
{
using var form = new EditLibraryDrawingForm(edit);
- return form.ShowDialog(this) == DialogResult.OK ? form.Saved : null;
+ return form.ShowDialog(DialogOwner) == DialogResult.OK ? form.Saved : null;
};
ChooseSet = () =>
{
using var form = new ChooseDrawingSetForm(sets, library, this.serverUrl);
- return form.ShowDialog(this) == DialogResult.OK ? (true, form.PickedSet) : (false, null);
+ return form.ShowDialog(DialogOwner) == DialogResult.OK ? (true, form.PickedSet) : (false, null);
};
EditSet = edit =>
{
using var form = new EditDrawingSetForm(edit, library, this.serverUrl);
- return form.ShowDialog(this) == DialogResult.OK ? form.Saved : null;
+ return form.ShowDialog(DialogOwner) == DialogResult.OK ? form.Saved : null;
};
ShowReleases = record =>
{
using var form = new DrawingSetsForm(sets, library, this.serverUrl);
enableSetsRelease(form);
_ = form.ShowReleasesAsync(drawing: record);
- form.ShowDialog(this);
+ form.ShowDialog(DialogOwner);
};
LoadPreview = async (record, token) =>
{
@@ -437,7 +443,7 @@ namespace OpenNest.Controls
using var form = new ReleaseSetForm(sets, library, nests, serverUrl, Array.Empty(),
new[] { new SetReleaseDrawingLine(record, quantity) }, openNest)
{ IsNestOpen = isNestOpen ?? (_ => false) };
- form.ShowDialog(this);
+ form.ShowDialog(DialogOwner);
};
enableSetsRelease = form => form.EnableRelease(nests, openNest, isNestOpen);
releaseSeparator.Visible = true;
diff --git a/OpenNest/Forms/EditNestForm.cs b/OpenNest/Forms/EditNestForm.cs
index 57215c39..8391b267 100644
--- a/OpenNest/Forms/EditNestForm.cs
+++ b/OpenNest/Forms/EditNestForm.cs
@@ -1177,7 +1177,7 @@ namespace OpenNest.Forms
PlateView.EndAction();
cutSimulatorForm = new CutSimulatorForm(this);
cutSimulatorForm.FormClosed += (_, _) => cutSimulatorForm = null;
- var owner = MdiParent ?? (Form)this;
+ var owner = DialogOwner;
var corner = owner.PointToScreen(new Point(owner.ClientSize.Width, owner.ClientSize.Height));
cutSimulatorForm.Show(owner);
cutSimulatorForm.Location = new Point(
@@ -1457,6 +1457,12 @@ namespace OpenNest.Forms
drawingListBox1.SaveToLibraryUnavailableReason = enabled ? null : NestStorage.DatabaseModeOnly;
}
+ ///
+ /// The top-level window that owns this tab's dialogs. An MDI child is a child window, and a
+ /// dialog owned by one is not kept above the main window, so it can fall behind it.
+ ///
+ private Form DialogOwner => MdiParent ?? this;
+
/// Opens the drawing library browser and lists whatever it added.
public void AddFromDrawingLibrary()
{
@@ -1483,7 +1489,7 @@ namespace OpenNest.Forms
// The dialog adds drawings and sets quantities as the operator works in it.
using var change = BeginChange("Drawing Library");
var job = (Nest.Material, Nest.Thickness);
- form.ShowDialog(this);
+ form.ShowDialog(DialogOwner);
if (form.AddedDrawings.Count > 0 || form.QuantitiesChanged)
{
change.MarkChanged();
@@ -1531,7 +1537,7 @@ namespace OpenNest.Forms
lastCutType, Environment.UserName);
// The library itself is on the server; the drawing's link to it is saved with the nest.
using var change = BeginChange("Save to Drawing Library");
- if (form.ShowDialog(this) != DialogResult.OK || form.Result == null)
+ if (form.ShowDialog(DialogOwner) != DialogResult.OK || form.Result == null)
{
change.Complete();
return;
@@ -1574,7 +1580,7 @@ namespace OpenNest.Forms
addingToSet = true;
try
{
- await new NestDrawingsToSet(this, sets, library, NestStorage.Settings.ServerUrl).RunAsync(Nest);
+ await new NestDrawingsToSet(DialogOwner, sets, library, NestStorage.Settings.ServerUrl).RunAsync(Nest);
}
finally
{