From your question and the comment you made to SAKyukov, the sequence of events you want appears to be:
ApplicationScan class (which I assume is Form based) has a button. When it is clicked, you create an instance of scanTicket (again, Form based) which does some work on the data. The user can then press a button in the scanTicket form, which will signal an event to the ApplicationScan instance, and close the scanTicket instance.
There are three ways to look at this: The simplest case is to have ApplicationScan display teh scanTicket with the ShowDialog method. This will "freeze" ApplicationScan until the scanTicket instance is closed.
If you can't use ShowDialog, but must use the Show method instead, then you will have to hook into the scanTicket events.
The next simplest is to have ApplicationScan hook into the scanTicket.FormClosing event.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx[
^] It can then access whatever information it needed from the scanTicket instance before it closes completely. THis requires no extra work on your part, other than to hook into an event:
scanTicket sc = new scanTicket();
sc.FormClosing += new EventHandler(scanTicket_Closing);
sc.Show();
...
void scanTicket_Closing(object sender, EventArgs e)
{
...
}
If you need a separate event, because there is another way to close scanTicket without signalling to ApplicationScan, then the easiest way is to do just that: create an event in scan Ticket, which ApplicationScan hooks into:
scanTicket sc = new scanTicket();
sc.WorkCompleted += new EventHandler(scanTicket_Completed);
sc.Show();
...
void scanTicket_Completed(object sender, EventArgs e)
{
scanTicket sc = sender as scanTicket;
if (sc != null)
{
...
}
}
And in scanTicket:
public event EventHandler WorkCompleted;
protected virtual void OnWorkCompleted(EventArgs e)
{
EventHandler eh = WorkCompleted;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnWorkCompleted(null);
}
}
"Thanks for your detail answer. Still i have problem. scanticket instance is created more than one form at a time while launching the application.
Example
1. ManaualEnter
2. BarCode
3. Applicationscan
4. Pluscode
All four form creating the instance in the same order one by one. After the pluscode create a instance applicationscan event scanTicket_Completed become null. I am creating instance while running the application. So when i click the button in scanticket scanTicket_Completed event shows null.
Could you help me please. Thanks in advance
Regards
Keshaavan - NK7 4 mins ago"
If you are creating a new instance with each form, then the new instance will not share any of the information with the others - this includes events. Why are you creating a new instance each time, if you want to share info? Why not have just one instance, which all four of your other forms connect to?