Compartilhar via


RangeValuePattern.SetValue(Double) Método

Definição

Define o valor associado ao elemento Automação da Interface do Usuário.

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

Parâmetros

value
Double

O novo valor do elemento.

Exceções

Quando value for menor que o valor mínimo ou maior que o valor máximo do elemento.

Exemplos

No exemplo a seguir, um AutomationElement que dá suporte ao RangeValuePattern padrão de controle tem seu valor definido como o valor mínimo específico do controle.

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

Comentários

O conjunto de valores real depende da implementação do controle. O controle pode arredondar a solicitação value para cima ou para baixo. Um cliente Automação da Interface do Usuário pode examinar a Value propriedade para determinar o valor atualizado real. O cliente também pode se registrar para um evento com alteração de propriedade na propriedade e examinar os valores antigos e novos retornados no AutomationPropertyChangedEventArgs.

Aplica-se a

Confira também