⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlhelper.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
                    rtWnd.Bottom = rect.Top + height;
                    flag = true;
                }
            }
            catch
            {
            }
            return flag;
        }

        public static bool MakeWindowRectCenterOnParent(ref Imps.Client.Utils.Win32.RECT rtWnd, Imps.Client.Utils.Win32.RECT rtParent)
        {
            bool flag = false;
            try
            {
                IntPtr pvParam = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Imps.Client.Utils.Win32.RECT)));
                if (!Imps.Client.Utils.Win32.NativeMethods.SystemParametersInfo(0x30, 0, pvParam, 0))
                {
                    return false;
                }
                Imps.Client.Utils.Win32.RECT rect = (Imps.Client.Utils.Win32.RECT) Marshal.PtrToStructure(pvParam, typeof(Imps.Client.Utils.Win32.RECT));
                int width = rtWnd.Width;
                int height = rtWnd.Height;
                int num3 = 0;
                int num4 = 0;
                if ((rtParent.Width != 0) || (rtParent.Height != 0))
                {
                    num3 = rtParent.Left + ((rtParent.Width - width) / 2);
                    num4 = rtParent.Top + ((rtParent.Height - height) / 2);
                    if (num3 < 0)
                    {
                        num3 = 0;
                    }
                    else if ((num3 + width) > rect.Width)
                    {
                        num3 = rect.Width - width;
                    }
                    if (num4 < 0)
                    {
                        num4 = 0;
                    }
                    else if ((num4 + height) > rect.Height)
                    {
                        num4 = rect.Height - height;
                    }
                }
                else
                {
                    num3 = (rect.Width - width) / 2;
                    num4 = (rect.Height - height) / 2;
                }
                flag = (num3 != rtWnd.Left) || (num4 != rtWnd.Top);
                if (flag)
                {
                    rtWnd.Left = num3;
                    rtWnd.Right = num3 + width;
                    rtWnd.Top = num4;
                    rtWnd.Bottom = num4 + height;
                }
            }
            catch
            {
            }
            return flag;
        }

        public static bool MakeWindowRectCenterOnScreen(ref Imps.Client.Utils.Win32.RECT rtWnd)
        {
            return MakeWindowRectCenterOnParent(ref rtWnd, Imps.Client.Utils.Win32.RECT.Empty);
        }

        public static bool MakeWindowRectValid(ref Imps.Client.Utils.Win32.RECT rtWnd)
        {
            bool flag = false;
            try
            {
                IntPtr pvParam = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Imps.Client.Utils.Win32.RECT)));
                if (!Imps.Client.Utils.Win32.NativeMethods.SystemParametersInfo(0x30, 0, pvParam, 0))
                {
                    return false;
                }
                Imps.Client.Utils.Win32.RECT rect = (Imps.Client.Utils.Win32.RECT) Marshal.PtrToStructure(pvParam, typeof(Imps.Client.Utils.Win32.RECT));
                int width = rtWnd.Width;
                int height = rtWnd.Height;
                if (rtWnd.Width > rect.Width)
                {
                    rtWnd.Left = rect.Left;
                    rtWnd.Right = rect.Right;
                    flag = true;
                }
                else if (rtWnd.Right > rect.Right)
                {
                    rtWnd.Right = rect.Right;
                    rtWnd.Left = rtWnd.Right - width;
                    flag = true;
                }
                else if (rtWnd.Left < rect.Left)
                {
                    rtWnd.Left = rect.Left;
                    rtWnd.Right = rtWnd.Left + width;
                    flag = true;
                }
                if (rtWnd.Height > rect.Height)
                {
                    rtWnd.Top = rect.Top;
                    rtWnd.Bottom = rect.Bottom;
                    return true;
                }
                if (rtWnd.Bottom > rect.Bottom)
                {
                    rtWnd.Bottom = rect.Bottom;
                    rtWnd.Top = rtWnd.Bottom - height;
                    return true;
                }
                if (rtWnd.Top < rect.Top)
                {
                    rtWnd.Top = rect.Top;
                    rtWnd.Bottom = rtWnd.Top + height;
                    flag = true;
                }
            }
            catch
            {
            }
            return flag;
        }

        public static void NudgeWindow(Form form)
        {
            new NudgeWindowHelper(form).NudgeWindow();
        }

        public static void NudgeWindow(Form form, int interval, int totalmillisecond)
        {
            new NudgeWindowHelper(form, interval, totalmillisecond).NudgeWindow();
        }

        public static bool RepositionFormOnScreenSizeChanged(Form form)
        {
            try
            {
                Imps.Client.Utils.Win32.RECT lpRect;
                if (!Imps.Client.Utils.Win32.NativeMethods.GetWindowRect(form.Handle, out lpRect))
                {
                    return false;
                }
                bool flag = MakeWindowRectValid(ref lpRect);
                if (flag)
                {
                    form.SetBounds(lpRect.Left, lpRect.Top, lpRect.Width, lpRect.Height, BoundsSpecified.All);
                }
                return flag;
            }
            catch
            {
                return false;
            }
        }

        public static void SetAcceptDigitOnly(Control ctrl)
        {
            SetAcceptDigitOnly(ctrl, true);
        }

        public static void SetAcceptDigitOnly(Control ctrl, bool value)
        {
            if (value)
            {
                ctrl.ImeMode = ImeMode.Disable;
                ctrl.ImeModeChanged += new EventHandler(ControlHelper.ctrl_ImeModeChanged);
                ctrl.KeyPress += new KeyPressEventHandler(ControlHelper.ctrlAcceptDigitOnly_KeyPress);
                ctrl.TextChanged += new EventHandler(ControlHelper.ctrlAcceptDigitOnly_TextChanged);
            }
            else
            {
                ctrl.KeyPress -= new KeyPressEventHandler(ControlHelper.ctrlAcceptDigitOnly_KeyPress);
                ctrl.TextChanged -= new EventHandler(ControlHelper.ctrlAcceptDigitOnly_TextChanged);
            }
        }

        public static void SetAcceptMobileNoOnly(Control ctrl)
        {
            SetAcceptSpecialCharsOnly(ctrl, _mobileNoChars);
        }

        public static void SetAcceptPasswordChar(Control ctrl)
        {
            SetAcceptPasswordChar(ctrl, true);
        }

        public static void SetAcceptPasswordChar(Control ctrl, bool value)
        {
            if (value)
            {
                ForceControlImeDisable(ctrl, true);
                ctrl.KeyPress += new KeyPressEventHandler(ControlHelper.ctrlAcceptPasswordChar_KeyPress);
            }
            else
            {
                ForceControlImeDisable(ctrl, false);
                ctrl.KeyPress -= new KeyPressEventHandler(ControlHelper.ctrlAcceptPasswordChar_KeyPress);
            }
        }

        public static void SetAcceptSpecialCharsOnly(Control ctrl, char[] szSpecial)
        {
            new SetControlAcceptSpecialChars(ctrl, szSpecial);
        }

        public static void SetDoubleBuffered(Control ctrl)
        {
            if (ctrl != null)
            {
                PropertyInfo property = typeof(Control).GetProperty("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.NonPublic | BindingFlags.Instance);
                if (property != null)
                {
                    property.SetValue(ctrl, true, null);
                }
            }
        }

        public static DialogResult ShowDialogCenterOnParent(Form form, IWin32Window parent, bool doDispose)
        {
            DialogResult result;
            try
            {
                Control ctrl = parent as Control;
                Form owner = LookupOwnedForm(ctrl);
                if (((owner != null) && owner.IsHandleCreated) && (owner.Visible && (owner.WindowState != FormWindowState.Minimized)))
                {
                    form.StartPosition = FormStartPosition.CenterParent;
                }
                else
                {
                    form.StartPosition = FormStartPosition.CenterScreen;
                }
                if ((owner != null) && owner.TopMost)
                {
                    form.TopMost = owner.TopMost;
                }
                result = form.ShowDialog(owner);
            }
            finally
            {
                if (doDispose)
                {
                    form.Dispose();
                }
            }
            return result;
        }

        public static void ShowFormCenterOnParent(Form form, IWin32Window parent)
        {
            if (form.Visible)
            {
                form.BringToFront();
                form.Activate();
            }
            else
            {
                Imps.Client.Utils.Win32.RECT lpRect;
                Imps.Client.Utils.Win32.RECT rtWnd = new Imps.Client.Utils.Win32.RECT();
                rtWnd.Right = rtWnd.Left + form.Width;
                rtWnd.Bottom = rtWnd.Top + form.Height;
                Form ownedForm = LookupOwnedForm(parent as Control);
                if ((((ownedForm != null) && ownedForm.IsHandleCreated) && (ownedForm.Visible && (ownedForm.WindowState != FormWindowState.Minimized))) && Imps.Client.Utils.Win32.NativeMethods.GetWindowRect(parent.Handle, out lpRect))
                {
                    MakeWindowRectCenterOnParent(ref rtWnd, lpRect);
                }
                else
                {
                    MakeWindowRectCenterOnScreen(ref rtWnd);
                }
                form.StartPosition = FormStartPosition.Manual;
                form.SetBounds(rtWnd.Left, rtWnd.Top, 0, 0, BoundsSpecified.Location);
                if ((ownedForm != null) && ownedForm.TopMost)
                {
                    form.TopMost = ownedForm.TopMost;
                }
                if (!form.ShowInTaskbar)
                {
                    form.Show(parent);
                }
                else
                {
                    form.Show();
                }
            }
        }

        public static void TryForceControlImeHangul(Control ctrl)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -