ACAT.Lib.Core.Utility.Windows.SetWindowSizePercent C# (CSharp) Метод

SetWindowSizePercent() публичный статический Метод

Partial maximize. Sets the window width to a percent of the display width.
public static SetWindowSizePercent ( IntPtr handle, WindowPosition scannerPosition, int percent ) : void
handle System.IntPtr handle of the window
scannerPosition WindowPosition which corner should the window be positioned at?
percent int percentage of display monitor width
Результат void
        public static void SetWindowSizePercent(IntPtr handle, WindowPosition scannerPosition, int percent)
        {
            Log.Debug("Entering...scannerPosition=" + scannerPosition.ToString() + " percent=" + percent.ToString());
            int screenOffset = 0;
            int moveX = 0;
            int moveY = 0;  // not really using Y-axis yet but something to keep in mind for the future

            if (percent <= 10)
            {
                return;
            }

            if (percent > 100)
                percent = 100;

            screenOffset = 100 - percent;

            if (handle != IntPtr.Zero)
            {
                Rectangle r = Screen.PrimaryScreen.WorkingArea;

                if (r.Width > 0 && r.Height > 0)
                {
                    Log.Debug("Resize window to " + (r.Width * percent) / 100 + ", " + r.Height);

                    switch (scannerPosition)
                    {
                        case WindowPosition.TopRight:
                            moveX = 0;
                            moveY = 0;
                            break;

                        case WindowPosition.TopLeft:
                            moveX = (r.Width * screenOffset) / 100;
                            moveY = 0;
                            break;

                        case WindowPosition.BottomLeft:
                            moveX = (r.Width * screenOffset) / 100;
                            moveY = 0;
                            break;

                        case WindowPosition.BottomRight:
                            moveX = 0;
                            moveY = 0;
                            break;
                    }

                    Log.Debug("screenOffset=" + screenOffset + " moveX=" + moveX.ToString() + " moveY=" + moveY.ToString());
                    User32Interop.SetWindowPos(handle.ToInt32(), 0, moveX, moveY, (r.Width * percent) / 100, r.Height, 0x0040 | 0x0004);
                }
            }
            else
            {
                Log.Debug("fgWnd is zero");
            }
        }