# LaunchFormOptions Basic Steps

**URL:** <https://www.epiusers.help/t/launchformoptions-basic-steps/63084>\
**Category:** Experts' Corner\
**Tags:** customization, e10\
**Created:** [December 29, 2019, 5:04pm UTC](https://www.epiusers.help/t/launchformoptions-basic-steps/63084 "2019-12-29T17:04:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [December 29, 2019, 5:47pm UTC](https://www.epiusers.help/t/launchformoptions-basic-steps/63084/2 "2019-12-29T17:47:19Z")

</div>

# LFO Basics

In ValueIn you can pass in whatever you like, for example.

**Form 1** Button Code:

```cs
LaunchFormOptions lfo = new LaunchFormOptions();
lfo.IsModal = true; // true will basically not allow the user to do anything on Form1 until Form2 is closed.
lfo.ValueIn = "Hey Mark Wonsil, Got Anymore Dad Jokes?";
ProcessCaller.LaunchForm(oTrans, "UDDMR", lfo);

```

I mean anything…

```cs
lfo.ValueIn = this.oTrans; // lets just passed all of oTrans - not recommended but yeah you could
lfo.ValueIn = 123;
lfo.ValueIn = new List<int>() { 2, 3, 7 };

```

Then on the Form you are calling, you can capture the **lfo** object and read the value, then you do with it whatever you wish on the other side.

**Form 2** Example (The Form you are Launching):  
_I did mine on the \_Shown Event because I wanted to seperate my \_Load code and dedicate an event of its own._

```cs
private void UD100Form_Shown(object sender, EventArgs e)
{
	// Check for Called
	if (UD100Form.LaunchFormOptions != null && UD100Form.LaunchFormOptions.Sender != null && UD100Form.LaunchFormOptions.ValueIn != null)
	{

		string lfoValue = UD100Form.LaunchFormOptions.ValueIn.ToString();
		string lfoSenderName = UD100Form.LaunchFormOptions.Sender.ToString();

		switch (lfoSenderName)
		{
			case "Erp.UI.Rpt.PackingSlipPrint.Transaction":
				DataSet dsShipDtl = ShipDtlSearchAdapter(lfoValue);

				foreach (DataRow ShipDtlRow in dsShipDtl.Tables[0].Rows)
				{
					jobNum = ShipDtlRow["JobNum"].ToString();
					AutoCreateRecordsByJobNum(jobNum);
				}

				break;

			case "Erp.UI.App.JobEntry.Transaction":
				jobNum = lfoValue;
				AutoCreateRecordsByJobNum(jobNum);
				break;
		}
	}
}

```

To Simplify all you really need on the other side to get started it:

```cs
	if (UD100Form.LaunchFormOptions != null && UD100Form.LaunchFormOptions.Sender != null && UD100Form.LaunchFormOptions.ValueIn != null)
	{
		string lfoValue = UD100Form.LaunchFormOptions.ValueIn.ToString();
       EpiMessageBox.Show("The Value Passed in is " + lfoValueIn, "Hi", MessageBoxButtons.OK, MessageBoxIcon.Error);
	}

```

* * *

# Extra Credit 1 - Communicate Closed Event

You can also communicate between the 2 forms and even detect the closing of the Form Called.

**Form 1:**

```cs
private void btnTest_Click(object sender, System.EventArgs args)
{
	LaunchFormOptions lfo = new LaunchFormOptions();
	lfo.ValueIn = this.oTrans._packNum;
	//lfo.ContextValue = this.CreateParamsList(whereClauseUD100A);
	lfo.IsModal = true;
	lfo.SuppressFormSearch = true;
	lfo.LaunchedFormClosed += new EventHandler(lfo_LaunchedFormClosed);
	//lfo.CallBackMethod = CallBackHandlerBAQReport;
	ProcessCaller.LaunchForm(oTrans, "UEVQRT01", lfo);
}

void lfo_LaunchedFormClosed(object sender, EventArgs e)
{
	if (((EpiBaseForm)sender).DialogResult == System.Windows.Forms.DialogResult.OK)
	{
		// Do MAGIC Here the sender or e object will have the called form data and LFO Object Result, it literally will send over the entire Object, oTrans info etc... 
	}
}

```

**Form 2:**

```cs
UD100Form.DialogResult = DialogResult.OK;
UD100Form.LaunchFormOptions.Result = "HELLO WORLD";

```

I actually use this when I have a BAQ Form and I want to “Auto-Print” I Launch it, hidden or even visible and then return result and close it.

* * *

# Extra Credit 2 - Call Back Methods

You can also register a CallBack Method, so Form2 can actually call a Method on Form1. This is one trick I learned from @josecgomez

```cs
lfo.CallBackMethod = CallBackHandlerBAQReport;

```

**Form 1:**

```cs
/**
* Helper which listens to Communication from the BAQ Report
* Invoke from the BAQ Report for example to Refresh UI
* After Printing has happened so the Shape shows up
*/
void CallBackHandlerBAQReport(object sender, object CallBackArgs)
{
	// Verify CallBack args exist
	if (CallBackArgs == null) {
		return;
	}

	// We are passing back a string
	switch (CallBackArgs.ToString())
	{
		case "Refresh":
			this.oTrans.Refresh();
			break;
	}
}

```

**Form 2:** (One being Launched):

```cs
if (BAQReportForm.LaunchFormOptions != null)
{
	if (BAQReportForm.LaunchFormOptions.CallBackMethod != null) {
		BAQReportForm.LaunchFormOptions.CallBackMethod(oTrans, "Refresh");
	}
}

```

Basically you can pass back anything as well

```cs
BAQReportForm.LaunchFormOptions.CallBackMethod(oTrans, "ANYTHING_I_WISH_HERE");

```

My Use Case for this is when I Update my Form1 Data using its Adapter on Form2 and then I send a refresh to the background form and it updates. But you can actually do that with the previous discussed method **Extra Credit 1 - Communicate Closed Event** as well.

_The same methods are used for example when you Print a Packing Slip and then the Customer Shipment Form updates with the green shape “Printed” or shows a Message Box…_

---

_[View the full topic](https://www.epiusers.help/t/launchformoptions-basic-steps/63084)._
