UI Automation-TransformPattern

表示一个可以在二维空间中移动,调整大小或旋转的控件。TransformPattern控件的主要方法有Move(移动控件),resize(调整控件大小)和rotate(旋转控件)。

示例:

      public static void TestTransformPattern()

        {

            Process adressbook = Process.Start(@"C:/Program Files/Outlook Express/wab.exe");

            Thread.Sleep(2000);

 

            //Get main window   "Address Book - Main Identity"

 

            AutomationElement addresswindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Address Book - Main Identity"));

            Thread.Sleep(2000);

 

            TransformPattern windowpattern = Utility.UIA.ControlPattern.Transformpattern.GetTransformPattern(addresswindow);

            windowpattern.Move(10, 0);

            Thread.Sleep(1000);

            windowpattern.Resize(200, 200);

            Thread.Sleep(2000);

            if (windowpattern.Current.CanRotate.ToString() == "True")

                windowpattern.Rotate(20);

           

            Thread.Sleep(1000);

 

 

        }

 

public static TransformPattern GetTransformPattern(

            AutomationElement targetControl)

        {

            TransformPattern transformPattern = null;

 

            try

            {

                transformPattern =

                    targetControl.GetCurrentPattern(TransformPattern.Pattern)

                    as TransformPattern;

            }

            catch (InvalidOperationException)

            {

                // object doesn't support the TransformPattern control pattern

                return null;

            }

 

            return transformPattern;

        }

 

 

 

        ///--------------------------------------------------------------------

        /// <summary>

        /// Calls the TransformPattern.Move() method for an associated

        /// automation element.

        /// </summary>

        /// <param name="transformPattern">

        /// The TransformPattern control pattern obtained from

        /// an automation element.

        /// </param>

        /// <param name="x">

        /// The number of screen pixels to move the automation element

        /// horizontally.

        /// </param>

        /// <param name="y">

        /// The number of screen pixels to move the automation element

        /// vertically.

        /// </param>

        ///--------------------------------------------------------------------

        public static void MoveElement(

            TransformPattern transformPattern, double x, double y)

        {

            try

            {

                if (transformPattern.Current.CanMove)

                {

                    transformPattern.Move(x, y);

                }

            }

            catch (InvalidOperationException)

            {

                // object is not able to perform the requested action

                return;

            }

        }

        /// <param name="height">

        /// The requested height of the automation element.

        /// </param>

        ///--------------------------------------------------------------------

        public static void ResizeElement(

            TransformPattern transformPattern, double width, double height)

        {

            try

            {

                if (transformPattern.Current.CanResize)

                {

                    transformPattern.Resize(width, height);

                }

            }

            catch (InvalidOperationException)

            {

                // object is not able to perform the requested action

                return;

            }

        }

        public static void RotateElement(

        TransformPattern transformPattern, double degrees)

        {

            try

            {

                if (transformPattern.Current.CanRotate)

                {

                    transformPattern.Rotate(degrees);

                }

            }

            catch (InvalidOperationException)

            {

                // object is not able to perform the requested action

                return;

            }

        }

 

 

你可能感兴趣的:(c,UI,object,null,action)