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.
This commit is contained in:
Kurt 2020-09-05 20:18:36 -07:00
parent 0203eb4017
commit a2ed2889a2
2 changed files with 15 additions and 0 deletions

View File

@ -93,6 +93,8 @@ private void B_Inject_Click(object sender, EventArgs e)
if (exist != null)
{
exist.Show();
exist.BringToFront();
exist.CenterToForm(this);
return;
}

View File

@ -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<T>() where T : Form => (T?)Application.OpenForms.Cast<Form>().FirstOrDefault(form => form is T);
public static void RemoveDropCB(object sender, KeyEventArgs e) => ((ComboBox)sender).DroppedDown = false;
/// <summary>
/// Centers the <see cref="child"/> horizontally and vertically so that its center is the same as the <see cref="parent"/>'s center.
/// </summary>
/// <param name="child"></param>
/// <param name="parent"></param>
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));
}
}
}