123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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<T>(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;
- }
- }
- }
|