冷月葬花魂 发表于 2015-1-16 22:33:23

ASP.NET教程之C#计划带图标和自界说色彩的ListBox

不过你如果学.net的话,你就不要选os了,这课比较底层的。你可以旁听数据库加上软件构件和中间件。(webservices和面向服务的课也应该听一听)计划  在一个点对点文件传输的项目中,我必要显现文件传输的及时信息:传输的文件列表和以后传输的文件,事先我想到了用ListBox,可是但我用了ListBox后,我发明它不克不及改动控件中文本想的色彩,因而我就想扩大一下ListBox控件------ListBoxEx。
  我的方针是给空间加上图标,还要能不时改动控件文本色彩。因而从ListBox派生类
publicclassListBoxEx:ListBox{…}
  为了操纵便利我为ListBoxEx的每项计划专门的类ListBoxExItem
publicclassListBoxExItem{…}
  为了坚持我这个控件与WinForm的尺度控件的操纵托言分歧,我又从头计划了两个汇合类:
publicclassListBoxExItemCollection:IList,ICollection,IEnumerator{}
//这个类相对尺度ListBox中的ObjectCollection,这个类作为ListBoxEx中的Items属性的范例
publicclassSelectedListBoxExItemCollection::IList,ICollection,IEnumerator{}
//这个类相对尺度ListBox中的SelectedObjectCollection,这个类作为ListBoxEx中的SelectedItems属性的范例
  上面看两个汇合类的完成:
  ListBoxExItemCollection的完成:为了做到对汇合(Items)的操纵可以实时反应到ListBoxEx的控件中以是,此类只是对ListBox中Items(ObjectCollection范例)作了一层包装,就是把ListBox中Items属性的一切办法的只需是object范例的参数都转换成ListBoxExItem,好比:
publicvoidRemove(ListBoxExItemitem)
{
 this._Items.Remove(item);//_Items为ObjectCollection范例
}
publicvoidInsert(intindex,ListBoxExItemitem)
{
 this._Items.Insert(index,item);
}
publicintAdd(ListBoxExItemitem)
{
 returnthis._Items.Add(item);
}
  由上可知,ListBoxExItemCollection中有一个机关函数来传送ListBox中的Items工具
privateObjectCollection_Items;
publicListBoxExItemCollection(ObjectCollectionbaseItems)
{
 this._Items=baseItems;
}
  而SelectedListBoxExItemCollection类的完成也用一样的办法,只不外是对SelectedObjectCollection包装而已。
  汇合完成后,再来看ListBoxExItem的完成:
  为了使它撑持图标和多种色彩增加以下成员
 
privateint_ImageIndex;
publicintImageIndex
{
 get{returnthis._ImageIndex;}
 set{this._ImageIndex=value;}
}
privateColor_ForeColor;
publicColorForeColor
{
 get{returnthis._ForeColor;}
 set
 {
  this._ForeColor=value;
  this.Parent.Invalidate();
 }
}
  固然另有:
privatestring_Text;
publicstringText
{
 get{returnthis._Text;}
 set{this._Text=value;}
}
  为了控件能准确显现此项的文本,还必需重写ToString()办法
publicoverridestringToString()
{
 returnthis._Text;
}
  再看ListBoxEx的完成:
  为了使控件可以自我绘制,以是:DrawMode=DrawMode.OwnerDrawFixed;
  为了掩盖基类的Items等相干属性增加
 
privateListBoxExItemCollection_Items;//在机关函数中创立
  同时还必要重写属性Items:
 newpublicListBoxExItemCollectionItems
{
 get
 {
  returnthis._Items;
 }
}
newpublicListBoxExItemSelectedItem//强迫转换为ListBoxExItem
{
 get{returnbase.SelectedItemasListBoxExItem;}
 set{base.SelectedItem=value;}
}
newpublicSelectedListBoxExItemCollectionSelectedItems//从头包装SelectedItems
{
 get
 {
  returnnewSelectedListBoxExItemCollection(base.SelectedItems);
 }
}
  为了撑持图标,增加一个图象列表imagelist
 privateImageListimageList;
publicImageListImageList
{
 get{returnthis.imageList;}
 set
 {
  this.imageList=value;
  this.Invalidate();//图象列表改动后即刻更新控件
 }
}
  而此控件的中心却在一个办法OnDrawItem,这个办法每当控件的项必要重绘时就被挪用
 
protectedoverridevoidOnDrawItem(System.Windows.Forms.DrawItemEventArgspe)
{
 pe.DrawBackground();//画背景
 pe.DrawFocusRectangle();//画边框
 Rectanglebounds=pe.Bounds;
 //Checkwhethertheindexisvalid
if(pe.Index>=0&&pe.Index<base.Items.Count)
{
 ListBoxExItemitem=this.Items;//获得必要绘制项的援用
 intiOffset=0;
//Iftheimagelistispresentandtheimageindexisset,drawtheimage
 if(this.imageList!=null)
 {
  if(item.ImageIndex>-1&&item.ImageIndex<this.imageList.Images.Count)
  {
   this.imageList.Draw(pe.Graphics,bounds.Left,bounds.Top,bounds.Height,bounds.Height,item.ImageIndex);//绘制图标
  }
  iOffset+=bounds.Height;//this.imageList.ImageSize.Width;
 }
 //Drawitemtext
 pe.Graphics.DrawString(item.Text,pe.Font,newSolidBrush(item.ForeColor),bounds.Left+iOffset,bounds.Top);//依据项的色彩绘制文本
 }
 base.OnDrawItem(pe);
 }
}
  到此为止,ListBoxEx以完全的完成,而且撑持可视化计划。
一个很大的类库。应用程序之所以难以跨平台,在于直接调用了特定平台的接口,而一个巨大的类库,就能极大地减少应用程序对平台的依赖。

谁可相欹 发表于 2015-1-19 16:27:27

这也就是最近几年来随着各种新的后台技术的诞生,CGI应用在Internet上越来越少的原因。CGI方式不适合大访问量的应用。

若相依 发表于 2015-1-27 22:32:47

主流网站开发语言之PHP:PHP的全名非常有趣,它是一个巢状的缩写名称——“PHP:HypertextPreprocessor”,打开缩写还是缩写。PHP是一种HTML内嵌式的语言(就像上面讲的ASP那样)。而PHP独特的语法混合了C,Java,Perl以及PHP式的新语法。它可以比CGI或者Perl更快速地执行动态网页。

因胸联盟 发表于 2015-2-5 12:43:02

由于JSP/Servlet都是基于Java的,所以它们也有Java语言的最大优点——平台无关性,也就是所谓的“一次编写,随处运行(WORA–WriteOnce,RunAnywhere)”。除了这个优点,JSP/Servlet的效率以及安全性也是相当惊人的。

深爱那片海 发表于 2015-2-11 20:55:15

HTML:当然这是网页最基本的语言,每一个服务器语言都需要它的支持,要学习,这个肯定是开始,不说了.

灵魂腐蚀 发表于 2015-3-11 05:42:51

我觉得什么语言,精通就好,你要做的就是比其他80%的人都厉害,你就能得到只有20%的人才能得到的高薪。

山那边是海 发表于 2015-3-25 03:28:42

Servlet的形式和前面讲的CGI差不多,它是HTML代码和后台程序分开的。它们的启动原理也差不多,都是服务器接到客户端的请求后,进行应答。不同的是,CGI对每个客户请求都打开一个进程(Process)。
页: [1]
查看完整版本: ASP.NET教程之C#计划带图标和自界说色彩的ListBox