2011-12-25 39 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

相關問題