現在、私は(MBG SimpleWizardライブラリを使用して)ウィザードを作成しています。私はいくつかのページを持っています。それらの間でデータを共有する方法として、クラスout DBManip DBController
が渡されます。メソッドでこのDBControllerを使用する必要がありますが、呼び出しはライブラリによって処理されるため、メソッドへの参照によってDBControllerを簡単に渡すことはできません。渡された参照をメソッドが変更できるプロパティにするにはどうしたらいいですか?メソッドに渡される渡された参照を作成する
クラスの初期化:
WizardHost host = new WizardHost();
using (host)
{
host.Text = Migration.Properties.Resources.AppName;
host.ShowFirstButton = false;
host.ShowLastButton = false;
host.WizardCompleted += new WizardHost.WizardCompletedEventHandler(this.Host_WizardCompleted);
DBManip DBController;
host.WizardPages.Add(1, new Page1());
host.WizardPages.Add(2, new Page2(out DBController));
host.WizardPages.Add(3, new Page3(out DBController));
host.WizardPages.Add(4, new Page4(out DBController));
host.LoadWizard();
host.ShowDialog();
}
コンストラクタ:
public Page2(out DBManip DBController)
{
this.InitializeComponent();
this.label1.Text = Migration.Properties.Resources.ExportDirectoryMessage;
this.exportDirTextbox.Text = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
方法:
private bool SetExportDirectory()
{
string exportDirectory = this.exportDirTextbox.Text;
// If a path is given, check if it's valid
// and set the pathExists boolean
if (!Directory.Exists(exportDirectory))
{
MessageBox.Show(Migration.Properties.Resources.InvalidPath);
return false;
}
// Initializing the object to manipulate the databases
exportDirectory = new DBManip(exportDirectory);
return true;
}
プロパティメソッドを呼び出します:
public bool PageValid
{
get { return SetExportDirectory(); }
}
申し訳ありませんがシンプルなものがありませんでした。私はかなり新しくC#
あなたがあなたのページクラス(ページ1、ページ2、などのすべてをしたいと言っています)を使って 'DBManip'の共通インスタンスへの参照を共有し、' SetExportDirectory'が 'DBManip'のインスタンスで何かをしたいのですか?どのクラスが 'SetExportDirectory'のメンバーですか? –
最初の質問には、はい。第2にはPageValidと同様にPage2のメンバです。 (Page1には参照が必要ないので、参照はありませんが、あなたはその考えを持っています)。 –
私はあなたが 'DBManip'をどのように使いたいかを推測することができますが、私はページクラスの中でどのようにDBManipの単一のインスタンスへの答えを提供しました。 –