当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C# 把指定控件显示在最上面

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 C# 把指定控件显示在最上面


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 197 ::
收藏到网摘: n/a


昨天有个朋友问我,怎么样处理重叠的控件,让指定的控件在最上面.我就很抓狂,很奇怪为什么会有这种需求,但昨天上班忙,没时间.今天早上来就写了一段代码试试,如下:SetMeTop是设置最上的函数,button1_Click是一个测试方法,经测试,这样是可行的.为什么要用一个ArrryList而不是直接用index来删除呢,是因为删除上层的一个控件后,会导致下面控件的index都加1,会产生一些异常.这只是一时乱写的函数.也许.net本身直接有方法来设置,我却不知道.呵呵..欢迎指教: [email protected]
void SetMeTop(object obj){ //原理:先添加的控件会在最上面,即可见次序是由index决定的. int index=this.Controls.GetChildIndex((Control)obj);//取得要置顶控件的index ArrayList AL=new ArrayList();//用来装入控件的容器 for(int i=0;i< index;i++)//把要置顶控件上面的控件都装入容器 AL.Add(this.Controls[i]); for(int i=0;i< AL.Count;i++) { //用一次删除和一次添加操作,让它上面的控件排到下面去. this.Controls.Remove((Control)AL[i]); this.Controls.Add((Control)AL[i]); }}private void button1_Click(object sender, System.EventArgs e){ SetMeTop(sender);}