How to generate an own event in a user control

1

What a good day everyone, diculpen I have the following question, is about how to make a custom event in c # something similar to VB if possible or not in C #

Visual Basic

<System.ComponentModel.DefaultEvent("_Click")>
Public Class Boton

Public Event _Click(ByVal bandera As Boolean)

End Class
    
asked by Lorenzo Molina 05.03.2018 в 21:18
source

1 answer

3

You can use delegates and events

public delegate void RecibidoEventHandler(byte[] body);
public event RecibidoEventHandler Recibido;

Then in your code to execute only "shoot" the event

Recibido(....)

For the observer / consumer of the event

objetoA.Recibido+= MiClaseDelObjeto_Recibido;

what it does is "point" to the method with the same signature

private async void MiClaseDelObjeto_Recibido(byte[] body){
  //acciones...
}

Link that can help you

answered by 05.03.2018 / 21:59
source