2012-05-07 137 views
0

什麼即時試圖做的是有,所以當在控制布爾設置爲false,即使是在一個文本框控件的自定義它觸發關閉此事件:控制使用自定義事件

Public Property isError As Boolean = False 

    Public Event IsInError As EventHandler 

    Private Sub textInError() Handles Me.IsInError 
     If isError = False Then 
      Me.BackColor = isErrorColor 
     End If 
    End Sub 

香港專業教育學院從來沒有真正使用之前,所以我不是很熟悉他們的事件處理程序,所以我很可能是這裏的錯誤道路上

感謝

回答

1

是的,你是在錯誤的軌道與此有關。聆聽你的自己的事件總是強烈地表明你錯了。你想寫一個屬性設置器。像這樣:

Public Property IsError() As Boolean 
    Get 
     Return hasError 
    End Get 
    Set(ByVal value As Boolean) 
     If value == hasError Then Return 
     hasError = value 
     If hasError Then 
      prevBackColor = Me.BackColor 
      Me.BackColor = isErrorColor 
      '' RaiseEvent IsInError(Me, EventArgs.Empty) '' If you still need the event 
     Else 
      Me.BackColor = prevBackColor 
     End If 
    End Set 
End Property 

Private hasError As Boolean 
Private prevBackColor As Color