共用方式為


IRangeValueProvider.SetValue(Double) 方法

定義

設定控制項的值。

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

參數

value
Double

要設定的值。

例外狀況

value 小於控制項的最小值或大於控制項的最大值。

範例

下列範例顯示自訂控制項的這個方法的其中一個可能實作。 自訂控制項會透過其基底色彩的 Alpha 值來顯示其範圍值。

/// <summary>
/// Sets the value of the control.
/// </summary>
/// <param name="value">
/// The value to set the control to.
/// </param>
/// <remarks>
/// For the purposes of this sample, the custom control displays 
/// its value through the alpha setting of its base color.
/// </remarks>
public void SetValue(double value)
{
    if (value < Minimum | value > Maximum)
    {
        throw new ArgumentOutOfRangeException();
    }
    else
    {
        Color color = customControl.controlColor;
        // Invoke control method on separate thread to avoid 
        // clashing with UI.
        // Use anonymous method for simplicity.
        this.customControl.Invoke(new MethodInvoker(delegate()
        {
            customControl.controlColor =
                Color.FromArgb((int)value, color);
            customControl.Refresh();
        }));
    }
}
''' <summary>
''' Sets the value of the control.
''' </summary>
''' <param name="value">
''' The value to set the control to.
''' </param>
''' <remarks>
''' For the purposes of this sample, the custom control displays 
''' its value through the alpha setting of its base color.
''' </remarks>
Public Sub SetValue(ByVal value As Double) Implements IRangeValueProvider.SetValue
    If value < Minimum Or value > Maximum Then
        Throw New ArgumentOutOfRangeException()
    Else
        Dim color As Color = customControl.controlColor
        ' Invoke control method on separate thread to avoid 
        ' clashing with UI.
        ' Use anonymous method for simplicity.
        Me.customControl.Invoke(New MethodInvoker(Sub()
            customControl.controlColor = Color.FromArgb(CInt(Fix(value)), color)
            customControl.Refresh()
        End Sub))
    End If
End Sub

備註

實際值集取決於控制項實作。 控制項可以四捨五入要求的 value 向上或向下。

適用於

另請參閱