2013-01-24 35 views
1

該程序有一個面板,其中包含一個文本框,面板每邊都有兩個按鈕。 每個按鈕都用作「下一個」(>>)和「上一個」(< <)導航。我希望能夠通過點擊'>>'導航到下一個面板,這將清除文本框。然後,當我點擊'< <'時,我想回到前一個面板,其中包含之前添加的數據的文本框。不過,我想要做到這一點,而不必創建兩個面板,並將可見性設置爲true或false(我能夠做到這一點)。我想通過僅使用一個面板來實現此目的,因此可以無限次地完成該過程。我希望這很清楚,如果您需要更多信息,請讓我知道。導航和記憶文本框數據

這裏是我的界面的圖像,以澄清事情:

enter image description here

回答

2

,因爲你有頁碼,爲什麼不創建一個列表(或使用字典的頁碼作爲重點) ,然後在按鈕處理程序中>>和< <收集當前頁面的文本(並將其放入列表或字典中),並將其替換爲上一頁(來自列表或字典)的文本。

代碼可能是這個樣子:

public partial class Form1 : Form 
{ 
    Dictionary<Decimal, String> TextInfo; 

    public Form1() 
    { 
     InitializeComponent(); 

     TextInfo= new Dictionary<Decimal, String>(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     numPage.Value = 1; 
    } 


    private void bnForward_Click(object sender, EventArgs e) 
    { 
     if (TextInfo.ContainsKey(numPage.Value)) 
     { 
      TextInfo[numPage.Value] = textBox1.Text; 
     } 
     else 
     { 
      TextInfo.Add(numPage.Value, textBox1.Text); 
     } 

     numPage.Value++; 

     if (TextInfo.ContainsKey(numPage.Value)) 
     { 
      textBox1.Text = TextInfo[numPage.Value]; 
     } 
     else 
     { 
      textBox1.Text = ""; 
     } 
    } 

    private void bnBack_Click(object sender, EventArgs e) 
    { 
     if (numPage.Value == 1) 
      return; 

     if (TextInfo.ContainsKey(numPage.Value)) 
     { 
      TextInfo[numPage.Value] = textBox1.Text; 
     } 
     else 
     { 
      TextInfo.Add(numPage.Value, textBox1.Text); 
     } 

     numPage.Value--; 

     if (TextInfo.ContainsKey(numPage.Value)) 
     { 
      textBox1.Text = TextInfo[numPage.Value]; 
     } 
     else 
     { 
      textBox1.Text = ""; 
     } 
    } 


    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 

    } 




} 
+0

聽起來不錯生病嘗試 – Tacit