一直对语法加亮编辑器控件非常感兴趣,想弄个过来在项目中show一把以挣点眼球。遂上网搜搜,发现 ActiproSoftware公司的SyntaxEditor是个好冬冬啊(SnippetCompiler就是用的这个控件),VS的功能它都基本实现了,流口水啊( http://www.chinaaspx.com/comm/dotnetbbs/Showtopic.aspx?Forum_ID=45&id=146786&PPage=8&Page=1)。
        但好东西都是要银子买的,人家要银子3000大洋,咱们穷人没办法,没银两,又搜不到,只好自己动手编了。边上网参考网友代码,加上废寝忘食三五天,雏形出来了,能满足一般性的代码加亮展示要求,免费奉送!

功能概述
     语法加亮
     加亮规则由XML文件进行配置
     AutoComplete(ctrl+shift+space)
     可控步数Undo/Redo
     全选、拷贝、粘贴快键(Ctrl+A, Ctrl+C, Ctrl+V)
     直接操作RTF文档格式,提高效率

效果 
   

示例代码

    this .txtSyntax.ConfigFile  =   " csharp.xml " ;

   
this .txtSyntax.AcceptsTab  =   true ;
   
this .txtSyntax.CaseSensitive  =   false ;
   
this .txtSyntax.Dock  =  System.Windows.Forms.DockStyle.Fill;
   
this .txtSyntax.FilterAutoComplete  =   true ;
   
this .txtSyntax.Location  =   new  System.Drawing.Point( 0 0 );
   
this .txtSyntax.MaxUndoRedoSteps  =   50 ;
   
this .txtSyntax.Name  =   " txtSyntax " ;
   
this .txtSyntax.Size  =   new  System.Drawing.Size( 464 257 );
   
this .txtSyntax.TabIndex  =   0 ;
   
this .txtSyntax.Text  =   " if then while begin " ;
   
this .txtSyntax.WordWrap  =   false ;

XML配置文件示例(csharp.xml)
<?xml version="1.0" encoding="utf-8"?>
<DescriptorCollection>
  <Descriptor>
    <Token>/*</Token>
    <CloseToken>*/</CloseToken>
    <Color>0,100,0</Color>
    <Font>宋体,20</Font>
    <DescriptorType>ToCloseToken</DescriptorType>
    <DescriptorRecognition>StartsWith</DescriptorRecognition>
    <UseForAutoComplete>False</UseForAutoComplete>
  </Descriptor>
  <Descriptor>
    <Token>[</Token>
    <CloseToken>]</CloseToken>
    <Color>255,0,0</Color>
    <Font>宋体,20</Font>
    <DescriptorType>ToCloseToken</DescriptorType>
    <DescriptorRecognition>StartsWith</DescriptorRecognition>
    <UseForAutoComplete>False</UseForAutoComplete>
  </Descriptor>
  <Descriptor>
    <Token>public</Token>
    <CloseToken />
    <Color>0,0,255</Color>
    <Font>宋体,20</Font>
    <DescriptorType>Word</DescriptorType>
    <DescriptorRecognition>WholeWord</DescriptorRecognition>
    <UseForAutoComplete>True</UseForAutoComplete>
  </Descriptor>
  ...
</DescriptorCollection>

下载地址/Files/surfsky/SyntaxTextBox.rar
源代码: /Files/surfsky/SyntaxTextBox_Src051207(pm08)_ver1.0.rar