c# - populate a listbox from a.. function? -


First of all I'm new to C #

I'm trying to do something like In the #Winforms app

When my app starts, a form is minimized in the system tray. When I double click it, it opens and sends a request to a qpid broker for some information, then a message is sent back, and in my app is received in a listener (I'm not sure the code Is relevant but I will post it in any form)

  Namespace MyApp {Public category MyListener: IMessageListener {Public Zero Message Transfer (IMS M) {// do stuff with m}} }  

which I try I am popping the list box that comes with the message received in the same way, but I do not know how to communicate with that specific form from the message transfer function

< P>

I would suggest that your audience has no information about how to present the messages. Instead, expose a phenomenon that can listen to the form:

  Event Message in Messaging Event Messages for Arguments: EventArgs {Public IMessage Message {get; Private set; } Public MessageEventArgs (IMessage Message) {message = message; }}  

In your audience:

  Public category MyListener: IMessageListener {public event EventHandler & lt; MessageEventArgs & gt; Message found; Public Zero Messaging Transfer (IMS M) {On Message Recycled (New Message Event Horns (M)); } Safe Wide On-Message Recovery (Message Event Eg E) {Event Handler & lt; Message Event Arguments & gt; Temp = Message received; If (temporarily! = Tap) {Temp (this, e); }}}  

Now you can add an event listener to your form and add message information to listboxes or any other kind of control.

Update
This is an example of how the event handler can hook in the context. IMessageListener interface

  • This code has two perceptions:
    • Event MessageReceived to IMessageListener
    • IMSSE is a property named text in the interface.

    Code sample:

      public partial class MainUI: form {private IMessageListener _messageListener; Public MENU () {Initialization (); _messageListener = new MyListener (); _messageListener.MessageReceived + = MessageListener_Message retrieved; } Zero MessageListener_MessageReceived (Object Sender, MessageEventArgs e) {_messageListBox.Items.Add (e.Message.Text); }}  

  • Comments