GOSTARIA DE FAZER ESTE CODIGO VIRAR UMA FUNCAO

MALA 14/12/2009 22:28:42
#329695
Private Sub Modelo_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Modelo.GotFocus
Dim Cls As New ClsTxt

Cls.MudarCorFundoTxt(sender, ClsTxt.CorFundoTxt.CorFundoAzul)

Cls = Nothing
End Sub

Private Sub Modelo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Modelo.KeyPress
Dim Cls As New ClsTxt

e.Handled = Cls.TestaDigitacao(sender, e.KeyChar, Me.Text)

Cls = Nothing
End Sub

Private Sub Modelo_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Modelo.LostFocus
Dim Cls As New ClsTxt

Cls.MudarCorFundoTxt(sender, ClsTxt.CorFundoTxt.CorFundoBranco)

Cls = Nothing
End Sub

Gostaria de criar esta funcao numa class e chamar de qualquer formulario(Private Sub AddAddHandler(ByVal C As Control))
Private Sub AddAddHandler(ByVal C As Control)
For Each ctr As Control In C.Controls
If (ctr.Controls.Count > 0) Then
AddAddHandler(ctr)
Else
If (TypeOf ctr Is TextBox) Then
Dim t As TextBox = DirectCast(ctr, TextBox)
AddHandler t.GotFocus, AddressOf Modelo_GotFocus
AddHandler t.LostFocus, AddressOf Modelo_LostFocus
AddHandler t.KeyPress, AddressOf Modelo_KeyPress
End If

If (TypeOf ctr Is MaskedTextBox) Then
Dim M As MaskedTextBox = DirectCast(ctr, MaskedTextBox)
AddHandler M.GotFocus, AddressOf Modelo_GotFocus
AddHandler M.KeyPress, AddressOf Modelo_KeyPress
End If
End If
Next
End Sub

nao sei como passar este codigo por paramentros
AddressOf Modelo_GotFocus

se alguem puder me ajudar, agradeço.
IRRV 14/12/2009 22:49:49
#329697
Resposta escolhida
Se foi o que entendi

AddHandler Modelo.GotFocus, New EventHandler(AddressOf Modelo_GotFocus)

Espero que ajude,

Att,
Tópico encerrado , respostas não são mais permitidas