コード例 #1
0
        public static Window syncWithControl(this Window window, System.Windows.Forms.Control control)
        {
            if (window.isNull())
            {
                "[API_GuiAutomation] in syncWithControl, provided window value was null".error();
                return(null);
            }
            Action moveToControl =
                () => {
                window.alwaysOnTop(true);
                var xPos   = control.PointToScreen(System.Drawing.Point.Empty).X;
                var yPos   = control.PointToScreen(System.Drawing.Point.Empty).Y;
                var width  = control.width();
                var height = control.height();
                window.move(xPos, yPos, width, height);
            };

            control.parentForm().Move +=
                (sender, e) => moveToControl();

            control.Resize +=
                (sender, e) => moveToControl();
            moveToControl();
            return(window);
        }