語言

TransformPattern.Rotate(Double) 方法

定義

旋轉控制器。

public:
 void Rotate(double degrees);
public void Rotate(double degrees);
member this.Rotate : double -> unit
Public Sub Rotate (degrees As Double)

參數

degrees
Double

旋轉元件的角度。 正數順時針旋轉;負數逆時針旋轉。

例外狀況

這個 CanRotate 屬性是假的。

範例

在以下範例中, 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.Rotate() method for an associated 
/// automation element.
/// </summary>
/// <param name="transformPattern">
/// The TransformPattern control pattern obtained from
/// an automation element.
/// </param>
/// <param name="degrees">
/// The amount of degrees to rotate the automation element.
/// </param>
///--------------------------------------------------------------------
private 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;
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Calls the TransformPattern.Rotate() method for an associated 
''' automation element.
''' </summary>
''' <param name="transformPattern">
''' The TransformPattern control pattern obtained from
''' an automation element.
''' </param>
''' <param name="degrees">
''' The amount of degrees to rotate the automation element.
''' </param>
'''--------------------------------------------------------------------
Private Sub RotateElement( _
ByVal transformPattern As TransformPattern, ByVal degrees As Double)
    Try
        If transformPattern.Current.CanRotate Then
            transformPattern.Rotate(degrees)
        End If
    Catch
        ' object is not able to perform the requested action
        Return
    End Try

End Sub

備註

物件無法被移動、調整大小或旋轉,使其產生的螢幕位置完全超出容器座標,且鍵盤或滑鼠無法存取。 例如,當頂層視窗完全移出畫面外,或子物件移出容器視窗的邊界時。 在這些情況下,物件會盡量靠近請求的螢幕座標,而頂部或左側的座標會被覆寫,以使其位於容器的邊界內。

適用於