You could register your currently opened bill child windows and unregister them when closing.
When the bill number in one window is changed you iterate through your single child window instances and set the new bill number according to the new entered one.
The most simple way to achieve the register/unregister mechanism would be a static class that holds a list with the window instances.
Possible solution:
Add a method
SetNumber
to your ChildForm, which sets the number in the bill number text box.
public void SetNumber(int number)
{
textBoxBillNo.Text = number.ToString();
}
Create a class called MdiHandler.
public class MdiHandler
{
private static List<ChildForm> mdiChilds = new List<ChildForm>();
public static void Register(ChildForm child)
{
if (!mdiChilds.Contains(child))
mdiChilds.Add(child);
}
public static void Unregister(ChildForm child)
{
if (mdiChilds.Contains(child))
mdiChilds.Remove(child);
}
public static void UpdateChilds(ChildForm child, int start)
{
int i = start;
foreach (ChildForm frm in mdiChilds)
if (frm != child)
frm.SetNumber(++i);
}
}
When creating a ChildForm object put in its
Load
event:
MdiHandler.Register(this);
To the
KeyPress
event of your bill number text box add the following code:
private void textBoxBillNo_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= '0') && (e.KeyChar <= '9'))
MdiHandler.UpdateChilds(this, int.Parse(textBox1.Text + e.KeyChar));
}
I hope that is what you want to achieve and helps you.