C#编程实现QQ界面的方法
本文实例讲述了C#编程实现QQ界面的方法。分享给大家供大家参考,具体如下:
步骤:
1.新建一个页面,假如说叫VerticalMenu
2.把html代码copy到html代码区
3.把LoadTopMenu方法copy到cs代码区
4.运行即可
1.html代码
<STYLEtype="text/css"> A:link{}{COLOR:#000000;FONT-SIZE:12px;TEXT-DECORATION:none} A:visited{}{COLOR:#000000;FONT-SIZE:12px;TEXT-DECORATION:none} A:hover{}{COLOR:#006CD9;FONT-SIZE:12px;TEXT-DECORATION:none} BODY{}{FONT-SIZE:12px;} TD{}{FONT-SIZE:12px;line-height:150%} </STYLE> <scriptlanguage="JavaScript"> <!-- functionshowitem(id,name) { //打开弹出式页面 //return("<span><ahref='"+id+"'target=_blank>"+name+"</a></span><br>") //在框架中打开 return("<span><ahref='#'onclick=/"url('"+id+"');/">"+name+"</a></span><br>") } functionurl(id) { varsource=document.getElementById('fMain'); source.src=id; } functionswitchoutlookBar(number) { vari=outlookbar.opentitle; outlookbar.opentitle=number; varid1,id2,id1b,id2b if(number!=i&&outlooksmoothstat==0){ if(number!=-1) { if(i==-1){ id2="blankdiv"; id2b="blankdiv"; } else{ id2="outlookdiv"+i; id2b="outlookdivin"+i; document.all("outlooktitle"+i).style.border="1pxnonenavy"; document.all("outlooktitle"+i).style.background=outlookbar.maincolor; document.all("outlooktitle"+i).style.color="#ffffff"; document.all("outlooktitle"+i).style.textalign="center"; } id1="outlookdiv"+number id1b="outlookdivin"+number document.all("outlooktitle"+number).style.border="1pxnonewhite"; document.all("outlooktitle"+number).style.background=outlookbar.maincolor;//title document.all("outlooktitle"+number).style.color="#ffffff"; document.all("outlooktitle"+number).style.textalign="center"; smoothout(id1,id2,id1b,id2b,0); } else { document.all("blankdiv").style.display=""; document.all("blankdiv").sryle.height="100%"; document.all("outlookdiv"+i).style.display="none"; document.all("outlookdiv"+i).style.height="0%"; document.all("outlooktitle"+i).style.border="1pxnonenavy"; document.all("outlooktitle"+i).style.background=outlookbar.maincolor; document.all("outlooktitle"+i).style.color="#ffffff"; document.all("outlooktitle"+i).style.textalign="center"; } } } functionsmoothout(id1,id2,id1b,id2b,stat) { if(stat==0){ tempinnertext1=document.all(id1b).innerHTML; tempinnertext2=document.all(id2b).innerHTML; document.all(id1b).innerHTML=""; document.all(id2b).innerHTML=""; outlooksmoothstat=1; document.all(id1b).style.overflow="hidden"; document.all(id2b).style.overflow="hidden"; document.all(id1).style.height="0%"; document.all(id1).style.display=""; setTimeout("smoothout('"+id1+"','"+id2+"','"+id1b+"','"+id2b+"',"+outlookbar.inc+")",outlookbar.timedalay); } else { stat+=outlookbar.inc; if(stat>100) stat=100; document.all(id1).style.height=stat+"%"; document.all(id2).style.height=(100-stat)+"%"; if(stat<100) setTimeout("smoothout('"+id1+"','"+id2+"','"+id1b+"','"+id2b+"',"+stat+")",outlookbar.timedalay); else { document.all(id1b).innerHTML=tempinnertext1; document.all(id2b).innerHTML=tempinnertext2; outlooksmoothstat=0; document.all(id1b).style.overflow="auto"; document.all(id2).style.display="none"; } } } functiongetOutLine() { outline="<table"+outlookbar.otherclass+">"; for(i=0;i<(outlookbar.titlelist.length);i++) { outline+="<tr><tdname=outlooktitle"+i+"id=outlooktitle"+i+""; if(i!=outlookbar.opentitle) outline+="nowrapalign=centerstyle='cursor:hand;background-color:"+outlookbar.maincolor+";color:#ffffff;height:20;border:1nonenavy'"; else outline+="nowrapalign=centerstyle='cursor:hand;background-color:"+outlookbar.maincolor+";color:white;height:20;border:1nonewhite'"; outline+=outlookbar.titlelist[i].otherclass outline+="onclick='switchoutlookBar("+i+")'><spanclass=smallFont>"; outline+=outlookbar.titlelist[i].title+"</span></td></tr>"; outline+="<tr><tdname=outlookdiv"+i+"valign=topalign=centerid=outlookdiv"+i+"style='width:100%" if(i!=outlookbar.opentitle) outline+=";display:none;height:0%;"; else outline+=";display:;height:100%;"; outline+="'><divname=outlookdivin"+i+"id=outlookdivin"+i+"style='overflow:auto;width:100%;height:100%'>"; for(j=0;j<outlookbar.itemlist[i].length;j++) outline+=showitem(outlookbar.itemlist[i][j].key,outlookbar.itemlist[i][j].title); outline+="</div></td></tr>" } outline+="</table>" returnoutline } functionshow() { varoutline; outline="<divid=outLookBarDivname=outLookBarDivstyle='width=100%;height:100%'>" outline+=outlookbar.getOutLine(); outline+="</div>" document.write(outline); } functiontheitem(intitle,instate,inkey) { this.state=instate; this.otherclass="nowrap"; this.key=inkey; this.title=intitle; } functionaddtitle(intitle) { outlookbar.itemlist[outlookbar.titlelist.length]=newArray(); outlookbar.titlelist[outlookbar.titlelist.length]=newtheitem(intitle,1,0); return(outlookbar.titlelist.length-1); } functionadditem(intitle,parentid,inkey) { if(parentid>=0&&parentid<=outlookbar.titlelist.length) { outlookbar.itemlist[parentid][outlookbar.itemlist[parentid].length]=newtheitem(intitle,2,inkey); outlookbar.itemlist[parentid][outlookbar.itemlist[parentid].length-1].otherclass="nowrapalign=leftstyle='height:5'"; return(outlookbar.itemlist[parentid].length-1); } else additem=-1; } functionoutlook() { this.titlelist=newArray(); this.itemlist=newArray(); this.divstyle="style='height:100%;width:100%;overflow:auto'align=center";//可以在这里设置对齐方式 this.otherclass="border=0cellspacing='0'cellpadding='0'style='height:100%;width:100%'valign=middlealign=center"; this.addtitle=addtitle; this.additem=additem; this.starttitle=-1; this.show=show; this.getOutLine=getOutLine; this.opentitle=this.starttitle; this.reflesh=outreflesh; this.timedelay=50; this.inc=10; this.maincolor="#336699" } functionoutreflesh() { document.all("outLookBarDiv").innerHTML=outlookbar.getOutLine(); } functionlocatefold(foldname) { if(foldname=="") foldname=outlookbar.titlelist[0].title for(vari=0;i<outlookbar.titlelist.length;i++) { if(foldname==outlookbar.titlelist[i].title) { outlookbar.starttitle=i; outlookbar.opentitle=i; } } } varoutlookbar=newoutlook(); vartempinnertext1,tempinnertext2,outlooksmoothstat outlooksmoothstat=0; <%=LoadVerticalMenu()%>//从数据库产生垂直菜单 //--> </script> <tableid="mnuList"style="WIDTH:150px;HEIGHT:100%"cellspacing="0"cellpadding="0"align="left" border="0"> <tr> <tdbgcolor="#F0F0E5"id="outLookBarShow"style="HEIGHT:100%"valign="top"align="middle" name="outLookBarShow"> <scriptlanguage="JavaScript"> <!-- locatefold("") outlookbar.show() //--> </script> </td> </tr> </table>
2.cs代码
publicclassVerticalMenu:System.Web.UI.Page { protectedDataRow[]father; protectedDataRow[]first; privatevoidPage_Load(objectsender,System.EventArgse) { //模拟QQ菜单 } publicstaticstringConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; GetDataSet#regionGetDataSet publicstaticDataSetGetDataSet(stringsql) { SqlDataAdaptersda=newSqlDataAdapter(sql,ConnectionString); DataSetds=newDataSet(); sda.Fill(ds); returnds; } #endregion protectedstringLoadVerticalMenu() { stringsqlFather="select*fromPowerSetting"; DataSetdsFather=GetDataSet(sqlFather); father=dsFather.Tables[0].Select("IsBoot=0","IsBoot"); stringmenu=""; foreach(DataRowdrfatherinfather) { menu+="vart;"; menu+="t=outlookbar.addtitle('"+drfather["Description"]+"');"; first=dsFather.Tables[0].Select("ParentID='"+Convert.ToInt32(drfather["ParentID"])+"'andIsBoot=1","IsBoot"); foreach(DataRowdrfirstinfirst) { menu+="outlookbar.additem('"+drfirst["Description"]+"',t,'"+drfirst["Url"]+"');"; } } returnmenu; } WebFormDesignergeneratedcode#regionWebFormDesignergeneratedcode overrideprotectedvoidOnInit(EventArgse) { // //CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner. // InitializeComponent(); base.OnInit(e); } /**//**//**////<summary> ///RequiredmethodforDesignersupport-donotmodify ///thecontentsofthismethodwiththecodeeditor. ///</summary> privatevoidInitializeComponent() { this.Load+=newSystem.EventHandler(this.Page_Load); } #endregion }
3.数据库脚本
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[PowerSetting]')andOBJECTPROPERTY(id,N'IsUserTable')=1) droptable[dbo].[PowerSetting] GO CREATETABLE[dbo].[PowerSetting]( [PowerSettingID][int]IDENTITY(1,1)NOTNULL,--id [ParentID][int]NOTNULL,--父节点id [Description][nvarchar](255)COLLATEChinese_PRC_CI_ASNULL,--菜单描述内容 [Icon][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL,--要显示图标 [Url][nvarchar](255)COLLATEChinese_PRC_CI_ASNULL,--url [Target][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL,--_self,_blank等 [CreateByID][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL,--创建人id [CreateON][datetime]NULL,--创建日期 [IsEnabled][bit]NULL,--是否可用 [IsBoot][int]NULL--是不是根节点;1是其他不是 )ON[PRIMARY] GO
更多关于C#相关内容感兴趣的读者可查看本站专题:《C#数据结构与算法教程》、《C#常见控件用法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》
希望本文所述对大家C#程序设计有所帮助。