0
我有代碼突出顯示當前焦點的文本框,以便爲用戶提供一個視覺提示。我的問題是,如果我有10個帶有文本框的表單,並且我想爲它們提供相同的代碼。我需要複製它還是可以使用全局方法?如果是這樣,一個例子會非常有幫助。謝謝。在多個表單中使用處理程序?
代碼如下。
Private Sub FocusChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim txt As TextBox = sender
If txt.Focused Then
txt.Tag = txt.BackColor
txt.BackColor = Color.AliceBlue
Else
txt.BackColor = txt.Tag
End If
End Sub
Private Sub CreateAccount_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctrl As TextBox In Me.Controls.OfType(Of TextBox)()
AddHandler ctrl.GotFocus, AddressOf FocusChanged
AddHandler ctrl.LostFocus, AddressOf FocusChanged
ctrl.Tag = ctrl.BackColor
Next
End Sub
Ty sir!正是我在找的東西。 – Meowbits