RangeValuePattern.RangeValuePatternInformation.SmallChange Propriété

Définition

Obtient la valeur de petite modification, unique à l’élément UI Automation, qui est ajoutée ou soustraite à la propriété elementsValue.

public:
 property double SmallChange { double get(); };
public double SmallChange { get; }
member this.SmallChange : double
Public ReadOnly Property SmallChange As Double

Valeur de propriété

Valeur de petite modification propre à l’élément UI Automation ou null si l’élément ne prend pas en charge SmallChange. La valeur par défaut est 0.0.

Exemples

Dans l’exemple suivant, un AutomationElement qui prend en charge le RangeValuePattern modèle de contrôle a sa valeur incrémentée ou décrémentée par la valeur spécifique au SmallChange contrôle.

SetRangeValue(targetControl[0], rangeValuePattern.Current.SmallChange, 1);
SetRangeValue(targetControl(0), rangeValuePattern.Current.SmallChange, 1)
///--------------------------------------------------------------------
/// <summary>
/// Sets the range value of the control of interest.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <param name="rangeValue">
/// The value (either relative or absolute) to set the control to.
/// </param>
/// <param name="rangeDirection">
/// The value used to specify the direction of adjustment.
/// </param>
///--------------------------------------------------------------------
private void SetRangeValue(
    AutomationElement targetControl,
    double rangeValue,
    double rangeDirection)
{
    if (targetControl == null || rangeValue == 0 || rangeDirection == 0)
    {
        throw new ArgumentException("Argument cannot be null or zero.");
    }

    RangeValuePattern rangeValuePattern =
        GetRangeValuePattern(targetControl);

    if (rangeValuePattern.Current.IsReadOnly)
    {
        throw new InvalidOperationException("Control is read-only.");
    }

    rangeValue = rangeValue * Math.Sign(rangeDirection);

    try
    {
        if ((rangeValue <= rangeValuePattern.Current.Maximum) ||
            (rangeValue >= rangeValuePattern.Current.Minimum))
        {
            rangeValuePattern.SetValue(rangeValue);
        }
    }
    catch (ArgumentOutOfRangeException)
    {
        // TO DO: Error handling.
    }
    catch (ArgumentException)
    {
        // TO DO: Error handling.
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Sets the range value of the control of interest.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <param name="rangeValue">
''' The value (either relative or absolute) to set the control to.
''' </param>
''' <param name="rangeDirection">
''' The value used to specify the direction of adjustment.
''' </param>
'''--------------------------------------------------------------------
Private Overloads Sub SetRangeValue( _
ByVal targetControl As AutomationElement, _
ByVal rangeValue As Double, ByVal rangeDirection As Double)
    If targetControl Is Nothing OrElse _
    rangeValue = 0 OrElse rangeDirection = 0 Then
        Throw New ArgumentException("Argument cannot be null or zero.")
    End If

    Dim rangeValuePattern As RangeValuePattern = _
    GetRangeValuePattern(targetControl)

    If rangeValuePattern.Current.IsReadOnly Then
        Throw New InvalidOperationException("Control is read-only.")
    End If

    rangeValue = rangeValue * Math.Sign(rangeDirection)

    Try
        If rangeValue <= rangeValuePattern.Current.Maximum OrElse _
        rangeValue >= rangeValuePattern.Current.Minimum Then
            rangeValuePattern.SetValue(rangeValue)
        End If
    Catch exc As ArgumentOutOfRangeException
        ' TO DO: Error handling.
    Catch exc As ArgumentException
        ' TO DO: Error handling.
    End Try

End Sub
///--------------------------------------------------------------------
/// <summary>
/// Obtains a RangeValuePattern control pattern from an 
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A RangeValuePattern object.
/// </returns>
///--------------------------------------------------------------------
private RangeValuePattern GetRangeValuePattern(
    AutomationElement targetControl)
{
    RangeValuePattern rangeValuePattern = null;

    try
    {
        rangeValuePattern =
            targetControl.GetCurrentPattern(
            RangeValuePattern.Pattern)
            as RangeValuePattern;
    }
    // Object doesn't support the 
    // RangeValuePattern control pattern
    catch (InvalidOperationException)
    {
        return null;
    }

    return rangeValuePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a RangeValuePattern control pattern from an 
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A RangeValuePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetRangeValuePattern( _
ByVal targetControl As AutomationElement) As RangeValuePattern
    Dim rangeValuePattern As RangeValuePattern = Nothing

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

    Return rangeValuePattern

End Function 'GetRangeValuePattern

S’applique à

Voir aussi