VB.NET 学习---(5)

前端之家收集整理的这篇文章主要介绍了VB.NET 学习---(5)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面的代码示例是一个事件处理程序,该处理程序在 Text 属性值更改时执行。 Control 类有几个名称模式为PropertyNameChanged方法,它们在相应的PropertyName值(PropertyName表示相应的属性名)更改时引发。

  1. Private Sub currencyTextBox_TextChanged(sender As Object,_
  2. e As EventArgs) Handles currencyTextBox.TextChanged
  3. Try
  4. ' Convert the text to a Double and determine if it is a negative number.
  5. If Double.Parse(currencyTextBox.Text) < 0 Then
  6. ' If the number is negative,display it in Red.
  7. currencyTextBox.ForeColor = Color.Red
  8. Else
  9. ' If the number is not negative,display it in Black.
  10. currencyTextBox.ForeColor = Color.Black
  11. End If
  12. Catch
  13. ' If there is an error,display the text using the system colors.
  14. currencyTextBox.ForeColor = SystemColors.ControlText
  15. End Try
  16. End Sub

猜你在找的VB相关文章