私は次のシナリオについて考えていました:さまざまなビューを保持するための列挙型を作成する
public enum Views{
First,Second, Manager,Third,
}
ボタン状態の列挙可能なものを作成します
public enum ButtonState{Start,Next,Cancel,Back,}
すべてのデータを保持するクラスを作成します
public class MyData
{
//properties here
//Also have a default constructor
public MyData()
{
}
}
次に、フォームで次の新しいアイテムを使用します。
Public Views MyViewState { get; set;}
Public ButtonState MyButtonState { get; set;}
Public MyData dataclass { get; set;}
Public Form1()
{
InitializeComponent();
MyViewState = Views.First;
MyButtonState = ButtonState.Start;
dataclass = new MyData(); //mostly at startup your class data is empty ...
ControlViews();
}
Public void ControlViews()
{
//Based on your Buttons you will do what each form is asked to do:
switch(MyButtonState)
{
case ButtonState.Start:
//Since this is your startup: you only need to show your next view and replace you MyViewState
MyViewState = Views.First;
///code for showing your view
Break;
case ButtonState.Next:
//Since this time you probably filled in data you need to know in which MyViewState you are
Switch (MyViewState)
{
Case Views.First:
//You want to keep your data
///Code for placing data into your dataclass
//After replacing the code, you then need to do some calculations and open the next view
///Code for calculations and placing this data in the form
///Code for opening the second view
MyViewState = Views.Second;
Break;
// you then need to do this for each MyViewState
}
Break;
}
}
この種のシステムを使用する利点は、すべてのデータがクラスに残り、ビューを表示/閉じるだけで済むことです。
それは私がこれに対抗する方法です。