TransformPattern.Move(Double, Double) Метод

Определение

Перемешает элемент управления.

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

Абсолютные экранные координаты левого края элемента управления.

y
Double

Абсолютные экранные координаты верхнего края элемента управления.

Исключения

Свойство CanMove имеет значение false.

Примеры

В следующем примере TransformPattern шаблон элемента управления получается из AutomationElement и затем используется для перемещения 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

Комментарии

Объект нельзя переместить, изменить размер или повернуть таким образом, чтобы его итоговое расположение экрана было полностью за пределами координат контейнера и было недоступно для клавиатуры или мыши. Например, если окно верхнего уровня полностью перемещается за пределы экрана или дочерний объект перемещается за границы окна просмотра контейнера. В таких случаях объект помещается как можно ближе к запрошенным координатам экрана, а верхние или левые координаты переопределяются в границах контейнера.

Применяется к