2013-01-24 36 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