From a2ed2889a27af4ebe6b26997685c408d1dfc0aa2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 5 Sep 2020 20:18:36 -0700 Subject: [PATCH] Bring injector window to original position if already open Show doesn't do anything if it's already hidden; we want to bring it to the front of the screen and then reposition it CenterParent. --- NHSE.WinForms/Subforms/PlayerItemEditor.cs | 2 ++ NHSE.WinForms/Util/WinFormsUtil.cs | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NHSE.WinForms/Subforms/PlayerItemEditor.cs b/NHSE.WinForms/Subforms/PlayerItemEditor.cs index f4b9cee..97c5fda 100644 --- a/NHSE.WinForms/Subforms/PlayerItemEditor.cs +++ b/NHSE.WinForms/Subforms/PlayerItemEditor.cs @@ -93,6 +93,8 @@ private void B_Inject_Click(object sender, EventArgs e) if (exist != null) { exist.Show(); + exist.BringToFront(); + exist.CenterToForm(this); return; } diff --git a/NHSE.WinForms/Util/WinFormsUtil.cs b/NHSE.WinForms/Util/WinFormsUtil.cs index 98151cf..4813efd 100644 --- a/NHSE.WinForms/Util/WinFormsUtil.cs +++ b/NHSE.WinForms/Util/WinFormsUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -68,5 +69,17 @@ internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines public static T? FirstFormOfType() where T : Form => (T?)Application.OpenForms.Cast
().FirstOrDefault(form => form is T); public static void RemoveDropCB(object sender, KeyEventArgs e) => ((ComboBox)sender).DroppedDown = false; + + /// + /// Centers the horizontally and vertically so that its center is the same as the 's center. + /// + /// + /// + internal static void CenterToForm(this Control child, Control parent) + { + int x = parent.Location.X + ((parent.Width - child.Width) / 2); + int y = parent.Location.Y + ((parent.Height - child.Height) / 2); + child.Location = new Point(Math.Max(x, 0), Math.Max(y, 0)); + } } }