I am working on a multi form project in C# and I am having issues with the forms data persisting when changing between tabs. Each tab will open the respective form as shown below.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadForm(new FormHome());
}
#region FORM CALLER
public void loadForm(object Form)
{
if (this.gunaPanelHome.Controls.Count > 0)
this.gunaPanelHome.Controls.RemoveAt(0);
Form fetched = Form as Form;
fetched.TopLevel = false;
fetched.BringToFront();
fetched.Dock = DockStyle.Fill;
this.gunaPanelHome.Controls.Add(fetched);
this.gunaPanelHome.Tag = fetched;
fetched.Show();
}
private void gunaHomeButton_Click(object sender, EventArgs e) => loadForm(new FormHome());
private void gunaDelayButton_Click(object sender, EventArgs e) => loadForm(new FormDelay());
private void gunaAssemButton_Click(object sender, EventArgs e) => loadForm(new FormAssembly());
private void gunaBuildButton_Click(object sender, EventArgs e) => loadForm(new FormBuilder());
private void gunaSettingsButton_Click(object sender, EventArgs e) => loadForm(new FormSettings());
#endregion
}
I have data in other forms that I want to keep throughout the tab changes, and was wondering if there was an easier way besides building a constructor that set data through each action change. Overall, I would like to just .hide() the current form in the window.