using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Ips.Library.DxpLib { public static class WinformExtensions { public static void ToFullScreen(this Form form, int screen = 0) { form.WindowState = FormWindowState.Maximized; form.StartPosition = FormStartPosition.Manual; form.Bounds = Screen.AllScreens[screen].Bounds; } public static void Invoke(this Control ctrl, Action action) { if (ctrl == null || ctrl.IsDisposed || !ctrl.IsHandleCreated) return; if (ctrl.InvokeRequired) { ctrl.Invoke(action); } else { action(); } } public static void BeginInvoke(this Control ctrl, Action action) { if (ctrl == null || ctrl.IsDisposed || !ctrl.IsHandleCreated) return; if (ctrl.InvokeRequired) { ctrl.BeginInvoke(action); } else { action(); } } public static T FindParent(this Control ctrl) where T : Control { T result = null; Control curCtrl = ctrl; while (true) { if (curCtrl == null) break; if (curCtrl.Parent is T) { result = (T)curCtrl.Parent; break; } else { curCtrl = curCtrl.Parent; } } return result; } public static bool IsDesignMode(this Control ctrl) { bool returnFlag = false; #if DEBUG if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) { returnFlag = true; } else if (Process.GetCurrentProcess().ProcessName == "devenv") { returnFlag = true; } #endif return returnFlag; } } }