RangeValuePattern.SetValue(Double) Methode

Definition

Legt den Wert fest, der dem BenutzeroberflächenautomatisierungUI Automation-Element zugeordnet ist.Sets the value associated with the BenutzeroberflächenautomatisierungUI Automation element.

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

Parameter

value
Double

Der neue Wert des Elements.The new value of the element.

Ausnahmen

value ist kleiner als der Mindestwert oder größer als der maximale Wert des Elements.value is less than the minimum or greater than the maximum value of the element.

Beispiele

Im folgenden Beispiel wird ein AutomationElement -Wert, der das RangeValuePattern -Steuerelement Muster unterstützt, auf den Steuerelement spezifischen Minimalwert festgelegt.In the following example, an AutomationElement that supports the RangeValuePattern control pattern has its value set to the control-specific minimum value.

SetRangeValue(targetControl[0], rangeValuePattern.Current.Minimum);
SetRangeValue(targetControl(0), rangeValuePattern.Current.Minimum)
///--------------------------------------------------------------------
/// <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>
///--------------------------------------------------------------------
private void SetRangeValue(
    AutomationElement targetControl,
    double rangeValue)
{
    if (targetControl == null)
    {
        throw new ArgumentException("Argument cannot be null.");
    }

    RangeValuePattern rangeValuePattern =
        GetRangeValuePattern(targetControl);

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

    try
    {
        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>
'''--------------------------------------------------------------------
Private Overloads Sub SetRangeValue( _
ByVal targetControl As AutomationElement, ByVal rangeValue As Double)
    If targetControl Is Nothing Then
        Throw New ArgumentException("Argument cannot be null.")
    End If

    Dim rangeValuePattern As RangeValuePattern = _
    GetRangeValuePattern(targetControl)

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

    Try
        rangeValuePattern.SetValue(rangeValue)
    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    

Hinweise

Der tatsächliche Wert hängt von der Implementierung des Steuer Elements ab.The actual value set depends on the control implementation. Das Steuerelement kann die angeforderte value nach oben oder unten aufrunden.The control might round the requested value up or down. Ein Benutzeroberflächenautomatisierungs-Client Value kann die-Eigenschaft überprüfen, um den tatsächlich aktualisierten Wert zu bestimmen.A UI Automation client can examine the Value property to determine the actual updated value. Der Client kann sich auch für ein Eigenschaften Änderungs Ereignis für die-Eigenschaft registrieren und die alten und neuen Werte untersuchen, AutomationPropertyChangedEventArgsdie in zurückgegeben werden.The client can also register for a property-changed event on the property and examine the old and new values returned in the AutomationPropertyChangedEventArgs.

Gilt für:

Siehe auch