Accessing textbox on form

I have inherited an Epicor project that has a Windows form drawn on top of the Epicor base form. I have been told that I now need to add a textbox control on that form and I have done so. I now wish to obtain the text that has been entered in the TextBox. I have the following. When I try to execute this (the Controls.Find) I get an index out of bounds error. I want to pass this text to another Epicor form. Does anyone see the error in my code here?

LaunchFormOptions lfo = new LaunchFormOptions();
lfo.IsModal = false;
lfo.ValueIn = “”;

	var txtSerialNumber = (TextBox)Controls.Find("txtPartSerial", true)[0];
	string strMessage = txtSerialNumber.ToString();
	Environment.SetEnvironmentVariable("SerialNumber", strMessage, EnvironmentVariableTarget.Process);
	ProcessCaller.LaunchForm(oTrans, "IMSALUS", lfo);

is “that form” the Epicor base form or the Windows form? And are you trying to pass info between them?


After a couple of re-reads, it looks like you added the control txtPartSerial to the Epicor form, and want its text to be available to the Windows form. The value will be “passed” via an environment variable.

I think the cosde whould be more like

string strMessage = txtPartSerial.Text;

no need to create the other variable that holds the reference to the control.

edit: (fixed code above)

Thank you. I will look at that.

Note that there was an error in my code above (it used to say txtSerialNumber when it should have been txtPartSerial)