2011-12-25 64 views
0

我C#实现一个向导,以这种方式:当我想移动到另一种形式,我需要关闭currnet(this.close),如何隐藏,而不会丢失它的数据一个WinForms形式

private static void MyInitialization() 
{ 
    WizardData wData = new WizardData(); 
    wData.FormToShow = WizardData.wizardForms.FirstStep; 
    Form step1 = new FirstStep(wData); 
    Form step2 = new SecondStep(wData); 
    Form step3 = new ThirdStep(wData); 
    while (wData.FormToShow != WizardData.wizardForms.Cancel) 
    { 
    switch (wData.FormToShow) 
    { 
     case WizardData.wizardForms.FirstStep: 
     { 
       step1.ShowDialog(); 
       break; 
     } 
     case WizardData.wizardForms.SecondStep: 
     { 
      step2.ShowDialog(); 
      break; 
     } 
     case WizardData.wizardForms.ThirdStep: 
     { 
      step3.ShowDialog(); 
      break; 
      } 
     } 

但我想使目前visibility=false,而且当我转到其他表单时,不会丢失当前表单中的数据?

private void btnNext_Click(object sender, EventArgs e) 
{ 
     // to show the SecondStep form 
     wData.FormToShow = WizardData.wizardForms.SecondStep; 
     this.Close(); 
} 

有什么想法吗?

+0

[在C#中为Windows窗体创建向导]的可能副本(http://stackoverflow.com/questions/2340566/creating-wizards-for-windows-forms-in-c-sharp) – 2011-12-25 13:36:23

回答

2

使用Hide()方法

Form1.Hide(); 

这种方式,表格将不可见,并且数据将被保存,直到您的形式Dispose()

+0

谢谢,工作正常,我能做些什么来避免表单之间的闪烁? – user1082943 2011-12-25 13:59:51

+0

闪烁是什么意思? – Shai 2011-12-25 14:10:50

+0

隐藏()和获取ShowDialog()的窗体之间的转换,而不是平滑。我可以修复它吗?谢谢。 – user1082943 2011-12-25 21:17:10

相关问题