帮助表格之间的导航 [英] help about navigation among forms

查看:87
本文介绍了帮助表格之间的导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我遇到了你的一篇文章。我有一个任务,我开发基于窗口的应用程序,它包含3个表单,我有3个表单,因为用户输入的信息将不适合一个表单。现在,当我接受第一个表格上的数据并移动第二个和之后到第三个并继续输入数据....当我导航回第一个表格并且当再次尝试再次移动到第二或第三个表格时,我松开了所有输入的数据。请帮我解决这个问题...我怎样才能保留数据?



i必须尽早解决这个问题...
$ b如果你能提供帮助,$ bi会感激你....还有哪里可以得到你的答复?

解决方案

首先,Krunal是对的 - 你很可能最好使用选项卡控件或类似功能,但这并不强制用户必须访问并完成每个页面。



如果没有看到您的代码,很难说执行此操作并且它将修复它,但您可能正在创建表单的新实例,而无需在其中复制任何信息。因此,用户看到的表单是空白的,因为(正确地)新表单不包含任何信息!



您需要做的是阅读来自的信息当用户单击确定或类似内容时,通过属性显示表单,并将其保存在主表单中以供日后使用。然后,您可以存储信息,或者在通过相同的属性重新显示信息时将其放回到表单中。


您应该将数据与UI分开(即从表单中分离) )。

假设你有一个(你自己的) UserInput 类的对象,包含所有需要的变量。

您应该使用相关的UserInput状态初始化每个表单。然后,在表单关闭时,您应该使用从表单收集的值更新对象相关状态。


您好,

为每个实体使用Classes并保留其类中的属性。例如,考虑我有两种形式,

1. 学生表格 - 输入学生的数据。 ex :(名称,部门和年份)

2. 学生成绩表 - 输入学生数据的标记。 ex :(考试,TotalMarks和平均值)

输入学生表格数据后,我将转到学生成绩单。现在创建两个类来保存表单数据,两个类,

1. StudentBasicInfo 类,

 < span class =code-keyword> class  StudentBasicInfo 
{
private string _Name;

public string 名称
{
get { return _Name; }
set {_ Name = value ; }
}

private string _Department;

public string 部门
{
get { return _Department; }
set {_Department = value ; }
}

private string _Year;

public string
{
get { return _Year; }
set {_Year = value ; }
}
}



2. StudentMarksInfo 类,

  class  StudentBasicInfo 
{
private string _Exam;

public string 考试
{
get { return _Exam; }
set {_Exam = value ; }
}

private double _TotalMarks;

public double TotalMarks
{
get { return _TotalMarks; }
set {_TotalMarks = value ; }
}

private string _Average;

public string 平均
{
get { return _Average; }
set {_Average = value ; }
}
}



现在我们有两个类,为 StudentBasicInfo 类创建一个对象并为<分配值b>表单中存在的受尊重TextBox的名称,部门和年份属性。对第二种形式做同样的事情。现在我们有两个带有用户提供的值的对象,当你回到一个表单时,使用这个对象并将它的值分配回TextBox。

并在windows窗体中引用DataBinding它将在这里有用场景。


Hello i came across one of your article. I have one assignment where i m developing window based application, it consists 3 forms, i have 3 forms as the information which user enter will not fit in one form. Now when i accept data on 1st form and move 2nd and after to 3rd and keep entering data.... when i navigate back to 1st form and when try to again move to 2nd or 3rd form i loose all data which has been entered. Please help me with this issue...how can i retain data??

i have to solve this issue as early as possible...
i would be thankful to you if you can help .... also where can i get your response??

解决方案

Firstly, Krunal is right - you are probably better off using a tab control or similar, but that doesn't enforce that the user must visit and complete each page.

Without seeing your code, it's difficult to say "do this" and it'll fix it, but the chances are that you are creating new instances of your forms without copying any information in or out of them. As a result, the form the user sees is blank because (correctly) a new form contains no information!

What you need to do is probably to read the information from the form via properties when the user clicks "OK" or similar, and save it in you main form for later. You can then store the info, or put it back into the form when you re-display it via the same properties.


You should separate your data from the UI (that is from the forms).
Suppose you have an object of the (your own) UserInput class, containing all the needed variables.
You should initialize every form using the relevant UserInput state. Then, at form closing, you should update the object relevant state using the values collected from the form.


Hi,
Use Classes for each entity and keep its properties inside the class. For example, consider I am having two forms,
1. Student Form - to enter Student's data. ex: (Name, Department and Year).
2. Student Marks Form - to enter marks of the student data. ex:(Exam, TotalMarks and Average).
After entering Student Form data, I am moving to Student Marks Form. Now create two classes to hold the form data, two classes,
1. StudentBasicInfo class,

class StudentBasicInfo
{
  private string _Name;
  
  public string Name
  {
    get { return _Name; }
    set { _Name = value; }
  }

  private string _Department;
  
  public string Department
  {
    get { return _Department; }
    set { _Department = value; }
  }

  private string _Year;
  
  public string Year
  {
    get { return _Year; }
    set { _Year = value; }
  }
}


2. StudentMarksInfo class,

class StudentBasicInfo
{
  private string _Exam;
  
  public string Exam
  {
    get { return _Exam; }
    set { _Exam = value; }
  }

  private double _TotalMarks;
  
  public double TotalMarks
  {
    get { return _TotalMarks; }
    set { _TotalMarks = value; }
  }

  private string _Average;
  
  public string Average
  {
    get { return _Average; }
    set { _Average = value; }
  }
}


Now we have two classes, Create an object for StudentBasicInfo class and assign values for Name, Department and Year properties from the respected TextBoxes present in the Form. Do the same for the second form. Now we have two object with user provided values, use this objects and assign its values back to the TextBoxes when you come back to a form.
And refer about DataBinding in windows forms it will be useful in this scenario.


这篇关于帮助表格之间的导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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