현재 (저는 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' 멤버인가요? –
첫 번째 질문은 그렇습니다. 두 번째로는 PageValid와 마찬가지로 Page2의 멤버입니다. (Page1에는 필요하지 않기 때문에 참조가 없지만 아이디어를 얻을 수 있습니다.) –
'DBManip'을 사용하고자하는 것만 추측 할 수 있지만, Page 클래스 중 하나의 DBManip 인스턴스에 대한 답을 제공했습니다. –