如何在不丢失数据的情况下在Windows窗体之间导航 [英] How to navigate between windows forms without loosing data

查看:99
本文介绍了如何在不丢失数据的情况下在Windows窗体之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我目前正在处理的多形式程序,并且我使用常规方法在表单之间导航以正常工作,例如:



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



并且:

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





这些工作正常,只是在开头的表格之间导航。 />
我现在遇到的问题是我需要能够导航回到以前的表格,而不会丢失任何页面上的数据。



我在表单之间导航,重要的是隐藏/关闭最后一个表单。不希望用户在使用当前表单时能够看到上一个表单(例如,当从form1转到form2时,表单1已经消失。当从form2转到表单1时,form2必须消失。) 。



程序的作用是填写程序中的所有表单,然后最后将数据保存到文件中。在另一个屏幕上,您可以查看表单中的数据。非常基本我知道,但我还在学习。



我尝试过:



我一直在尝试在每个表单之间传递数据,以及我在互联网上找到的不同表单导航。什么是成功的,在做什么,我需要做的又

解决方案
简单:使用ShowDialog的,但首先隐藏:

 private void newBtn_Click(object sender,EventArgs e)
{
newReport1 nr1 = new newReport1();
隐藏();
nr1.ShowDialog();
Show();
string value = nr1.MyPropertyFromTheReportForm;
}





看看这些:

在两个表格之间传递信息,第1部分:父母与孩子 [ ^ ]

在两个表格之间传递信息,第2部分:孩子到家长 [ ^ ]

在两种表格之间传递信息,第3部分:儿童与儿童 [ ^ ]


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.

解决方案

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[^]


这篇关于如何在不丢失数据的情况下在Windows窗体之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆