次の方法で共有


TransformPattern.TransformPatternInformation.CanMove プロパティ

定義

UI オートメーション要素を移動できるかどうかを示す値を取得します。

public:
 property bool CanMove { bool get(); };
public bool CanMove { get; }
member this.CanMove : bool
Public ReadOnly Property CanMove As Boolean

プロパティ値

要素を移動できる場合は true。それ以外の場合は 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

注釈

オブジェクトを移動、サイズ変更、または回転することはできません。これにより、結果の画面の位置がコンテナーの座標の外に完全に外れ、キーボードやマウスにアクセスできなくなります。 たとえば、最上位のウィンドウが画面から完全に移動した場合や、子オブジェクトがコンテナーのビューポートの境界の外に移動した場合などです。 このような場合、オブジェクトは要求された画面座標の近くに可能な限り配置され、上または左の座標はコンテナーの境界内にオーバーライドされます。

適用対象