读书人

C#中小弟我将四个panel叠在一起loca

发布时间: 2012-06-06 16:44:11 作者: rapoo

C#中我将四个panel叠在一起,location和size相同,然后换页?但是会出现问题,下面是代码,求各位高手帮忙分析一下,解决小弟的问题!
private int clickpage = 0;//点击次数;
//下一页,方法。
private void nextpage()
{
switch(clickpage)
{
case 1:
this.panel1.Visible=false;
this.panel2.Visible=true;
this.button2.Enabled = true;
break;
case 2:
this.panel2.Visible=false;
this.panel3.Visible=true;
break;
case 3:
this.panel3.Visible=false;
this.panel4.Visible=true;
this.button3.Enabled = false;
break;
default :
break;
}
}
//下一页
private void button3_Click(object sender, EventArgs e)
{
clickpage++;
this.nextpage();
}

//上一页 方法
private void uppage()
{
switch(clickpage)
{
case 0:
this.panel1.Visible=true;
this.panel2.Visible=false;
this.button2.Enabled = false;
break;
case 1:
this.panel2.Visible=true;
this.panel3.Visible=false;
break;
case 2:
this.panel3.Visible=true;
this.panel4.Visible=false;
this.button3.Enabled = true;
break;
default:
break;
}

}
//上一页
private void button2_Click(object sender, EventArgs e)
{
clickpage--;
uppage();
}

[解决办法]
把4个panel放在一个Panel[]数组中,有助于你的代码精练。
Panel[] panels = new Panel[]{panel1, panel2, panel3, panel4};
private void uppage()

for(int i=0; i < 4;i ++)
panels[i].Visible = clickpage = i;

[解决办法]

C# code
switch(clickpage)  {  case 1:   [color=#FF0000]  this.panel2.BringToFront(); [/color]  this.button2.Enabled = true;  break;  case 2:     [color=#FF0000] this.panel3.BringToFront();[/color]  break;  case 3:  [color=#FF0000]  this.panel4.BringToFront();[/color]  this.button3.Enabled = false;  break;  default :  break;  }  } 

读书人网 >C#

热点推荐