The three numbers equate the argb for red
604 | CHAPTER 20 |
|
|
---|---|---|---|
Listing 20.1: |
|
Public Sub New(ByVal InitValue As Int32)
' Initialize the properties.If (InitValue >= 0) And (InitValue <= 100) Then
_CompareValue = InitValue
Else
Throw New ArgumentOutOfRangeException( _
"InitValue", InitValue, _
"InitValue must be between 0 and 100")
End If
End Sub
CREATING STANDARD COMPONENTS | 605 |
---|
' Return a color based on the current value of _CompareValue.
If (_CompareValue >= 0) And (_CompareValue <= 33) Then
Return Colors.Green
End If
The Set portion of the property uses the same technique as the second constructor to change the _CompareValue value. Always check every input to reduce the risk of getting a bad input value.
The CalcColor() method doesn’t accept any input value. You could certainly create an override that would accept the comparison value as input. The method performs a numeric comparison and returns an enumerated color value based on the input. Using the technique shown reduces the risk of misinterpreting the method output.