从当前形式到以前的形式 [英] From current form to previous form

查看:196
本文介绍了从当前形式到以前的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有2种形式,可在textBox,comboBox等中输入一些数据,
当我转到第二种形式并回到第一种形式时,我输入的所有数据都会刷新.即Form1没有值.
当我从FORM2移到FORM1时,请有人帮我在form1中显示这些值.调用Form1.Hide)并在需要时使用Form1.Show将其显示回来.


您可以将该值存储在设置中...为此
打开项目属性....
选择设置选项卡,然后输入变量名称,变量的数据类型,然后选择范围作为用户,如果要提供任何默认值,请最后输入...
之后,创建一个属性来访问该变量,然后以两种形式创建该属性,或者您可以为常见的静态类中的该属性创建一个静态属性...

public string FirstValue
{
    get { return Properties.Settings.Default.DestinationPath; }
    set
    {
         if (value != Properties.Settings.Default.FirstValue)
         {
             Properties.Settings.Default.FirstValue = value;
             Properties.Settings.Default.Save();
         }
    }
}


根据您的应用程序的需要创建其他变量...
并直接访问它,或通过您之前创建的属性来使用它...
现在您可以从任何形式的应用程序访问此变量...
谢谢&问候,
Punit Parmar


形成协作的最佳方法是通过表单类实现适当的接口.
请查看我过去的解决方案中的详细信息,另请参阅其他解决方案和讨论:
如何在列表框之间复制所有项目两种形式 [ ^ ].

—SA


Hi,

I have 2 forms in which i enter some data in textBox, comboBox, etc.,
When i go to second form and come back to first form, all the data which i entered are refreshed. i.e., Form1 has no values.
Someone please help me displaying those values in form1 when i move from FORM2 to FORM1.

解决方案

Another way is to keep the Form1 is memory ( instead of Form1.close , invoke Form1.Hide) and show it back by using Form1.Show as an when required.


you can store that value in settings... for that
open your project properties....
select Settings tab and enter your variable name, Data Type of variable and select scope as user and last if you want give any default value then give it...
after that create one property to access that variable create this property in both form or you can create one static property for that in common static class...

public string FirstValue
{
    get { return Properties.Settings.Default.DestinationPath; }
    set
    {
         if (value != Properties.Settings.Default.FirstValue)
         {
             Properties.Settings.Default.FirstValue = value;
             Properties.Settings.Default.Save();
         }
    }
}


create other variables as per need of your application...
and access it directly or use it through property that you have created before...
now you can access this variable from any form of your application...
Thanks & Regards,
Punit Parmar


The best way to form collaboration is implementing appropriate interface by the form class.
Please see the details in my past solution, see also other solutions and discussion:
How to copy all the items between listboxes in two forms[^].

—SA


这篇关于从当前形式到以前的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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