Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            var el = Element.Get(context);

            if (el == null)
            {
                throw new ArgumentException("element cannot be null");
            }
            var screen      = Screen.Get(context);
            var x           = X.Get(context);
            var y           = Y.Get(context);
            var width       = Width.Get(context);
            var height      = Height.Get(context);
            var animatemove = AnimateMove.Get(context);
            var windowstate = WindowState.Get(context);

            if (width <= 30 || height <= 10)
            {
            }
            else
            {
                var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                if (screen < 0)
                {
                    Log.Warning("screen cannot be below 0, using screen 0");
                    screen = 0;
                }
                if (screen >= allScreens.Count)
                {
                    Log.Warning("screen " + screen + " does not exists, using " + (allScreens.Count - 1) + " instead");
                    screen = allScreens.Count - 1;
                }
                x += allScreens[screen].WorkingArea.X;
                y += allScreens[screen].WorkingArea.Y;
                var _window = ((UIElement)el).GetWindow();
                var window  = new UIElement(_window);
                if (_window.Properties.NativeWindowHandle.IsSupported)
                {
                    GenericTools.Restore(_window.Properties.NativeWindowHandle.Value);
                }
                if (animatemove)
                {
                    window.MoveWindowTo(x, y, width, height);
                }
                if (!animatemove)
                {
                    window.SetWindowSize(width, height);
                    window.SetWindowPosition(x, y);
                }
                if (!string.IsNullOrEmpty(windowstate) && _window.Properties.NativeWindowHandle.IsSupported)
                {
                    switch (windowstate)
                    {
                    case "Normal": GenericTools.Restore(_window.Properties.NativeWindowHandle.Value); break;

                    case "Minimized": GenericTools.Minimize(_window.Properties.NativeWindowHandle.Value); break;

                    case "Maximized": GenericTools.Maximized(_window.Properties.NativeWindowHandle.Value); break;
                    }
                }
            }
        }