using PKHeX.Core;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using static PKHeX.Core.MessageStrings;
using Exception = System.Exception;
namespace PKHeX.WinForms;
public static class WinFormsUtil
{
internal static void TranslateInterface(Control form, string lang) => form.TranslateInterface(lang);
///
/// 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)
{
if (parent == null)
return;
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));
}
///
/// Horizontally centers the to the 's horizontal center.
///
internal static void HorizontallyCenter(this Control child, Control parent)
{
int midpoint = (parent.Width - child.Width) / 2;
if (child.Location.X != midpoint)
child.SetBounds(midpoint, 0, 0, 0, BoundsSpecified.X);
}
public static T? FirstFormOfType() where T : Form => (T?)Application.OpenForms.Cast