Click here to Skip to main content
15,849,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a multiform program that I am currently working on, and I have got navigation between the forms to work fine using the normal methods, for example:

private void newBtn_Click(object sender, EventArgs e)
        {
            newReport1 nr1 = new newReport1();
            nr1.ShowDialog();
        }

And:
private void newBtn_Click(object sender, EventArgs e)
{
    newReport1 nr1 = new newReport1();
    nr1.Show();
    this.Hide();
}


These have worked fine in order to just navigate between the forms in the beginning.
The issue I have now is that I need to be able to navigate back to a previous form without losing the data on either page.

When I navigate between the forms it is important that the last form is hidden/closed as well. Don't want the user to be able to see the previous form while they are working with the current form (e.g. When going from form1 to form2, form 1 is gone. When going from form2 to form 1, form2 must be gone.).

What the program does is that you fill in all the forms in the program, and then at the end, it saves the data to a file. And on another screen, you can view the data in the forms. Very basic I know but I'm still learning.

What I have tried:

I have been experimenting with passing data between each form, as well as different form navigation that I've found on the internet. Nothing has been successful at doing what I need it to do yet.
Posted
Updated 3-Aug-18 3:43am

1 solution

Simple: use ShowDialog, but Hide first:
private void newBtn_Click(object sender, EventArgs e)
    {
        newReport1 nr1 = new newReport1();
        Hide();
        nr1.ShowDialog();
        Show();
        string value = nr1.MyPropertyFromTheReportForm;
    }


And have a look at these:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900