elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  AddHandler Con [Delegate].CreateDelegate [Solucionado]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: AddHandler Con [Delegate].CreateDelegate [Solucionado]  (Leído 1,893 veces)
Keyen Night


Desconectado Desconectado

Mensajes: 496


Nothing


Ver Perfil
AddHandler Con [Delegate].CreateDelegate [Solucionado]
« en: 4 Septiembre 2011, 20:23 pm »

Quiero crear hacer un Handler con Delegate, me explico, normalmente uno hace un Handler así:

Código
  1.    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.        MessageBox.Show("Hola")
  3.    End Sub

Usando la instrucción Handles

Yo quiero hacerlo así:

Código
  1.  
  2.  
  3.    Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  4.        MessageBox.Show("Hola")
  5.    End Sub
  6.  
  7.        Dim MethodName As String = "Button1_Click"
  8.        Dim HandlerType As Type = GetType(EventHandler)
  9.        Dim MethodI As MethodInfo = Me.GetType.GetMethod(MethodName)
  10.  
  11.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.        Dim MethodName As String = "Button1_Click"
  13.        Dim HandlerType As Type = GetType(EventHandler)
  14.        Dim MethodI As MethodInfo = Me.GetType.GetMethod(MethodName)
  15.        Dim DelegateEvent As [Delegate] = _
  16.        [Delegate].CreateDelegate( _
  17.        HandlerType, _
  18.        MethodI, _
  19.        True)
  20.  
  21.        AddHandler Button1.Click, DelegateEvent
  22.  
  23. End Sub

Cuando creo el DelegateEvent da el error Error al enlazar con el método de destino.

No sé si este bien, ¿Qué está mal hecho?

Lo he logrado con este código

Código
  1.    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.        Dim MethodName As String = "Button4_Click"
  3.        Dim HandlerType As Type = GetType(EventHandler)
  4.        Dim MethodI As MethodInfo = Me.GetType.GetMethod(MethodName)
  5.        Dim DelegateEvent As [Delegate] = _
  6.        [Delegate].CreateDelegate( _
  7.        HandlerType, _
  8.        Me, _
  9.        MethodName)
  10.  
  11.        AddHandler Button4.Click, DelegateEvent
  12.  
  13.    End Sub


« Última modificación: 4 Septiembre 2011, 20:40 pm por Keyen Night » En línea

La Fé Mueve Montañas...
                                    ...De Dinero

La programación es más que un trabajo es más que un hobby es una pasión...
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[SOLUCIONADO] y [NO SOLUCIONADO]
Sugerencias y dudas sobre el Foro
Hans el Topo 7 3,001 Último mensaje 20 Enero 2007, 14:04 pm
por Cobac
[Solucionado]Buscar en Textbox |@@|[Solucionado]Ordenar de Mayor a menor
Programación Visual Basic
agus0 6 7,678 Último mensaje 13 Septiembre 2009, 01:33 am
por agus0
SOlucionado
PHP
alexkof158 2 2,259 Último mensaje 12 Noviembre 2009, 22:46 pm
por :ohk<any>
[SOLUCIONADO] como poner [SOLUCIONADO] a un tema
Sugerencias y dudas sobre el Foro
jcrack 5 4,131 Último mensaje 25 Febrero 2011, 21:55 pm
por jcrack
c# a vbnet delegate
.NET (C#, VB.NET, ASP)
j0selit0_vaca 0 1,817 Último mensaje 18 Diciembre 2011, 16:39 pm
por j0selit0_vaca
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines