C#编程实现QQ界面的方法
程序员文章站
2022-05-14 17:43:56
本文实例讲述了c#编程实现qq界面的方法。分享给大家供大家参考,具体如下:
步骤:
1.新建一个页面,假如说叫verticalmenu
2.把html代码copy到h...
本文实例讲述了c#编程实现qq界面的方法。分享给大家供大家参考,具体如下:
步骤:
1.新建一个页面,假如说叫verticalmenu
2.把html代码copy到html代码区
3.把loadtopmenu方法copy到cs代码区
4.运行即可
1.html代码
<style type="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> <script language="javascript"> <!-- function showitem(id,name) { //打开弹出式页面 //return ("<span><a href='"+id+"' target=_blank>"+name+"</a></span><br>") //在框架中打开 return ("<span><a href='#' onclick=/"url('"+id+"');/">"+name+"</a></span><br>") } function url(id) { var source = document.getelementbyid('fmain'); source.src=id; } function switchoutlookbar(number) { var i = outlookbar.opentitle; outlookbar.opentitle=number; var id1,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="1px none navy"; 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="1px none white"; 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="1px none navy"; document.all("outlooktitle"+i).style.background=outlookbar.maincolor; document.all("outlooktitle"+i).style.color="#ffffff"; document.all("outlooktitle"+i).style.textalign="center"; } } } function smoothout(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"; } } } function getoutline() { outline="<table "+outlookbar.otherclass+">"; for (i=0;i<(outlookbar.titlelist.length);i++) { outline+="<tr><td name=outlooktitle"+i+" id=outlooktitle"+i+" "; if (i!=outlookbar.opentitle) outline+=" nowrap align=center style='cursor:hand;background-color:"+outlookbar.maincolor+";color:#ffffff;height:20;border:1 none navy' "; else outline+=" nowrap align=center style='cursor:hand;background-color:"+outlookbar.maincolor+";color:white;height:20;border:1 none white' "; outline+=outlookbar.titlelist[i].otherclass outline+=" onclick='switchoutlookbar("+i+")'><span class=smallfont>"; outline+=outlookbar.titlelist[i].title+"</span></td></tr>"; outline+="<tr><td name=outlookdiv"+i+" valign=top align=center id=outlookdiv"+i+" style='width:100%" if (i!=outlookbar.opentitle) outline+=";display:none;height:0%;"; else outline+=";display:;height:100%;"; outline+="'><div name=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>" return outline } function show() { var outline; outline="<div id=outlookbardiv name=outlookbardiv style='width=100%;height:100%'>" outline+=outlookbar.getoutline(); outline+="</div>" document.write(outline); } function theitem(intitle,instate,inkey) { this.state=instate; this.otherclass=" nowrap "; this.key=inkey; this.title=intitle; } function addtitle(intitle) { outlookbar.itemlist[outlookbar.titlelist.length]=new array(); outlookbar.titlelist[outlookbar.titlelist.length]=new theitem(intitle,1,0); return(outlookbar.titlelist.length-1); } function additem(intitle,parentid,inkey) { if (parentid>=0 && parentid<=outlookbar.titlelist.length) { outlookbar.itemlist[parentid][outlookbar.itemlist[parentid].length]=new theitem(intitle,2,inkey); outlookbar.itemlist[parentid][outlookbar.itemlist[parentid].length-1].otherclass=" nowrap align=left style='height:5' "; return(outlookbar.itemlist[parentid].length-1); } else additem=-1; } function outlook() { this.titlelist=new array(); this.itemlist=new array(); this.divstyle="style='height:100%;width:100%;overflow:auto' align=center";//可以在这里设置对齐方式 this.otherclass="border=0 cellspacing='0' cellpadding='0' style='height:100%;width:100%'valign=middle align=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" } function outreflesh() { document.all("outlookbardiv").innerhtml=outlookbar.getoutline(); } function locatefold(foldname) { if (foldname=="") foldname = outlookbar.titlelist[0].title for (var i=0;i<outlookbar.titlelist.length;i++) { if(foldname==outlookbar.titlelist[i].title) { outlookbar.starttitle=i; outlookbar.opentitle=i; } } } var outlookbar=new outlook(); var tempinnertext1,tempinnertext2,outlooksmoothstat outlooksmoothstat = 0; <%=loadverticalmenu()%>//从数据库产生垂直菜单 //--> </script> <table id="mnulist" style="width:150px;height: 100%" cellspacing="0" cellpadding="0" align="left" border="0"> <tr> <td bgcolor="#f0f0e5" id="outlookbarshow" style="height: 100%" valign="top" align="middle" name="outlookbarshow"> <script language="javascript"> <!-- locatefold("") outlookbar.show() //--> </script> </td> </tr> </table>
2.cs代码
public class verticalmenu : system.web.ui.page { protected datarow[] father; protected datarow[] first; private void page_load(object sender, system.eventargs e) { // 模拟qq菜单 } public static string connectionstring=system.configuration .configurationsettings .appsettings["connectionstring"]; getdataset#region getdataset public static dataset getdataset(string sql) { sqldataadapter sda =new sqldataadapter(sql,connectionstring); dataset ds=new dataset(); sda.fill(ds); return ds; } #endregion protected string loadverticalmenu() { string sqlfather="select * from powersetting"; dataset dsfather=getdataset(sqlfather); father=dsfather.tables[0].select("isboot=0","isboot"); string menu=""; foreach(datarow drfather in father) { menu+="var t;"; menu+="t=outlookbar.addtitle('"+drfather["description"]+"');"; first=dsfather.tables[0].select("parentid='"+convert.toint32(drfather["parentid"])+"' and isboot=1","isboot"); foreach(datarow drfirst in first) { menu+="outlookbar.additem('"+drfirst["description"]+"',t,'"+drfirst["url"]+"');"; } } return menu; } web form designer generated code#region web form designer generated code override protected void oninit(eventargs e) { // // codegen: this call is required by the asp.net web form designer. // initializecomponent(); base.oninit(e); } /**//**//**//// <summary> /// required method for designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void initializecomponent() { this.load += new system.eventhandler(this.page_load); } #endregion }
3.数据库脚本
if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[powersetting]') and objectproperty(id, n'isusertable') = 1) drop table [dbo].[powersetting] go create table [dbo].[powersetting] ( [powersettingid] [int] identity (1, 1) not null , --id [parentid] [int] not null , --父节点id [description] [nvarchar] (255) collate chinese_prc_ci_as null , --菜单描述内容 [icon] [nvarchar] (50) collate chinese_prc_ci_as null , --要显示图标 [url] [nvarchar] (255) collate chinese_prc_ci_as null , --url [target] [nvarchar] (50) collate chinese_prc_ci_as null , --_self,_blank等 [createbyid] [nvarchar] (50) collate chinese_prc_ci_as null , --创建人id [createon] [datetime] null , --创建日期 [isenabled] [bit] null , --是否可用 [isboot] [int] null --是不是根节点;1是其他不是 ) on [primary] go
更多关于c#相关内容感兴趣的读者可查看本站专题:《c#数据结构与算法教程》、《c#常见控件用法教程》、《c#面向对象程序设计入门教程》及《c#程序设计之线程使用技巧总结》
希望本文所述对大家c#程序设计有所帮助。