Application.Run(form) how to receive messages from the "form" c#

372 views Asked by At

I am stuck on understanding how after starting the message loop with Application.Run(Form) i can receive back data from the internal app.

My question is, How can I retrieve messages, objects, strings, etc? Basically I want that my internal application to send back an object to the main winform to be able to utilize the main form code to execute a USB print. Is this possible? and if it is can someone help me with a very simple example of string printText = "hello there"; and grab that onto the main winform for processing? Sorry I know it is not the prettiest of questions, but I should be able to start from there.

My winform application is executing some legacy code of windows CE, and the data I am processing in it I need to be able to print to a USB printer.

1

There are 1 answers

1
Gurpreet On BEST ANSWER

I assume that when you say internal app, you mean child form. so best thing to do is to create event on child form, this event will be handled by the main form. so whenever you need some data in main form then your child form can pass this data in event argument. now your main form will handle this event and to whatever with this data.

In main form

var childForm=new ChildForm();
childForm.DataGenerated+=DataHandler;
childForm.Show();

private void DataHandler(object data)
{
    //do something with data
}