TransformPattern.Move(Double, Double) 方法

定义

移动此控件。Moves the control.

public:
 void Move(double x, double y);
public void Move (double x, double y);
member this.Move : double * double -> unit
Public Sub Move (x As Double, y As Double)

参数

x
Double

此控件左侧的绝对屏幕坐标。Absolute screen coordinates of the left side of the control.

y
Double

此控件顶部的绝对屏幕坐标。Absolute screen coordinates of the top of the control.

例外

CanMove 属性为 false。The CanMove property is false.

示例

在下面的示例中,将 TransformPattern 从获取一个控件模式, AutomationElement 并随后用于移动 AutomationElementIn the following example, a TransformPattern control pattern is obtained from an AutomationElement and subsequently used to move the AutomationElement.

///--------------------------------------------------------------------
/// <summary>
/// Obtains a TransformPattern control pattern from 
/// an automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A TransformPattern object.
/// </returns>
///--------------------------------------------------------------------
private 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>
''' Obtains a TransformPattern control pattern from 
''' an automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A TransformPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTransformPattern( _
ByVal targetControl As AutomationElement) As TransformPattern
    Dim transformPattern As TransformPattern = Nothing

    Try
        transformPattern = DirectCast( _
        targetControl.GetCurrentPattern(transformPattern.Pattern), _
        TransformPattern)
    Catch exc As InvalidOperationException
        ' object doesn't support the TransformPattern control pattern
        Return Nothing
    End Try

    Return transformPattern

End Function 'GetTransformPattern    
///--------------------------------------------------------------------
/// <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>
///--------------------------------------------------------------------
private 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;
    }
}
'''--------------------------------------------------------------------
''' <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>
'''--------------------------------------------------------------------
Private Sub MoveElement( _
ByVal transformPattern As TransformPattern, _
ByVal x As Double, ByVal y As Double)
    Try
        If transformPattern.Current.CanMove Then
            transformPattern.Move(x, y)
        End If
    Catch exc As InvalidOperationException
        ' object is not able to perform the requested action
        Return
    End Try

End Sub

注解

不能移动、调整大小或旋转对象,使其生成的屏幕位置完全在其容器的坐标之外并且无法通过键盘或鼠标访问。An object cannot be moved, resized, or rotated such that its resulting screen location would be completely outside the coordinates of its container and inaccessible to keyboard or mouse. 例如,当顶级窗口完全移离屏幕或子对象移动到容器的视区边界之外时。For example, when a top-level window is moved completely off-screen or a child object is moved outside the boundaries of the container's viewport. 在这种情况下,将对象放置在尽可能靠近所请求的屏幕坐标的位置,并将其重写为位于容器边界内。In these cases the object is placed as close to the requested screen coordinates as possible with the top or left coordinates overridden to be within the container boundaries.

适用于