How to pass value to dynamic form

1 week ago 8
ARTICLE AD BOX

I need to solve passing value with dynamic form, below is the explanation

MainForm with menu and status bar on bottom side of windows. The status bar (lbBulkForm) indicate active form and (lbBulkField) indicate request field. Picture1

As an example, I will fill out the cargo manifest. When filling in the country field (tbCountryID), take it from the country master data.

When pressing the button "Get", update status bar value on MainForm (lbBulkForm) become active form name (Form2) and field to be filled (textBox3). Picture2 and similar when opening Addess Book (Form1) Picture3

Still on picture number 2, when Form3 (Country Master Data) open, initialize and load status bar from MainMenu status bar. originForm(Form2) and originField(textBox3).

Send back to origin form based on status bar value originForm (Form2) and field (textBox3).

I was success send back value to origin form and field statically, and need help solution to make dynamically. Below is the source code for each form.

MainForm_code

namespace DynamicPassingValue { public partial class MainForm : Form { public static MainForm Instance; public MainForm() { InitializeComponent(); Instance = this; } private void btAddressBook_Click(object sender, EventArgs e) { Form1 form = new Form1(); form.Show(); } private void btCargoManifest_Click(object sender, EventArgs e) { Form2 form = new Form2(); form.Show(); } private void btCountryMaster_Click(object sender, EventArgs e) { Form3 form = new Form3(); form.Show(); } } }

Form2_code

namespace DynamicPassingValue { public partial class Form2 : Form { public static Form2 Instance; public Form2() { InitializeComponent(); Instance = this; } private void btGet_Click(object sender, EventArgs e) { //Get Active Form var lastOpenedForm = Application.OpenForms.Cast<Form>().Last(); MainForm form = (MainForm)Application.OpenForms["MainForm"]; //Update status bar on bottom of MainForm and fields to be filled in form.lbBulkForm.Text = lastOpenedForm.Name; form.lbBulkField.Text = textBox3.Name; Form3 nform = new Form3(); nform.Show(); } } }

Form3_code

namespace DynamicPassingValue { public partial class Form3 : Form { public static Form3 Instance; public string originForm; public string originField; public Form3() { InitializeComponent(); Instance = this; originForm = MainForm.Instance.lbBulkForm.Text; originField = MainForm.Instance.lbBulkField.Text; } private void Form3_Load(object sender, EventArgs e) { label1.Text = originForm; label2.Text = originField; } private void btSendBack_Click(object sender, EventArgs e) { //Form1.Instance.Controls[originField].Text = tbCountryID.Text; /Value success passing to form1 //Form2.Instance.Controls[originField].Text = tbCountryID.Text; //Value success passing to form2 // Need help solve passing value to origin form dynamically //NeedSomeCommandHereToMakeDynamically Controls[originField].Text = tbCountryID.Text; } } }

Form1_code similar with Form2

Note: Properties field-to-be-filled on each form, Modifier was change to Public.

Read Entire Article