CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

求html文本编辑控件

楼主xiandaliu(仙达流,菜鸟先飞)2005-01-10 09:36:49 在 .NET技术 / C# 提问

不需要很复杂,只要关键字着色就好,速度要快,我自己写了一个速度很慢,由于使用的是richtextbox,用这个控件的selectioncolor属性改变关键字的颜色,其他都很快,只有执行richtextbox的select()方法和使用selectioncolor属性着色时候非常非常的慢,能解决这个问题也可以,^_^  
  问题点数:100、回复次数:13Top

1 楼xiandaliu(仙达流,菜鸟先飞)回复于 2005-01-10 09:42:31 得分 0

附代码如下:  
  类:拆分字符串  
  public   class   Html  
  {  
  public   struct   ColorText  
  {  
  public   Color   TextColor;  
  public   int   Index;  
  public   int   Length;  
  public   ColorText(   Color   textcolor,int   index,int   length   )  
  {  
  TextColor   =   Color.Black;   Index   =   -1;   Length   =   -1;  
  TextColor   =   textcolor;  
  Index   =   index;  
  Length   =   length;  
  }  
  }  
   
  public   static   ArrayList   Tag()  
  {  
  ArrayList   arr   =   new   ArrayList();  
  System.IO.FileStream   fs   =   new   System.IO.FileStream("d:\\WORDFILE.TXT",   System.IO.FileMode.Open,   System.IO.FileAccess.Read);  
  System.IO.StreamReader   srm   =   new   System.IO.StreamReader(fs);  
  string   TheFile   =   srm.ReadToEnd();  
  srm.Close();  
  fs.Close();  
  System.IO.StringReader   sr   =   new   System.IO.StringReader(TheFile);  
  string   nextLine;  
   
  nextLine   =   sr.ReadLine();  
  nextLine   =   nextLine.Trim().ToLower();  
  while   (nextLine   !=   null)  
  {  
  nextLine   =   nextLine.Trim().ToLower();  
  arr.AddRange(nextLine.Split('   '));  
  nextLine   =   sr.ReadLine();  
  }  
  System.IO.StreamWriter   sw   =   new   System.IO.StreamWriter("d:\\test.txt");  
  foreach   (string   st   in   arr)  
  sw.WriteLine(st);  
  sw.Flush();  
  sw.Close();  
  return   arr;  
  }  
  static   ArrayList   tag;  
  public   static   ArrayList   DrawText(   string   s   )  
  {  
  ArrayList   wr   =   new   ArrayList();  
  System.Text.RegularExpressions.Regex   r;  
  System.Text.RegularExpressions.Match   m;  
  r   =   new   System.Text.RegularExpressions.Regex(@"<\w+>|<\w+|"+"\""+"\\w+"+"\""+@"|</\w+>|[^A-Za-z0-9_<>   \f\t\v]|\w+",   System.Text.RegularExpressions.RegexOptions.IgnoreCase   |   System.Text.RegularExpressions.RegexOptions.Compiled);  
  if   (tag   ==   null)  
  {  
  tag   =   Tag();  
  tag.Sort();  
  }  
  int   count   =   0;  
  for   (m   =   r.Match(s);   m.Success;   m   =   m.NextMatch())  
  {  
  if   (tag.BinarySearch(m.Value.ToLower())   >=   0)  
  wr.Add(new   ColorText(Color.DarkRed,   m.Index,   m.Length));  
  else  
  wr.Add(new   ColorText(Color.Black,   m.Index,   m.Length));  
   
  count++;  
  }  
  return   wr;  
  }  
  }  
   
   
  RichTextBox   CustomControl  
  public   class   RichTextBox   :   System.Windows.Forms.RichTextBox  
  {  
  public   RichTextBox()  
  {  
  }  
   
  bool   _Paint   =   true;  
  string   _texttype   =   "html";  
  public   string   TextType  
  {  
  get   {   return   _texttype;   }  
  set   {   _texttype   =   value;   }  
  }  
   
  protected   override   void   WndProc(ref   System.Windows.Forms.Message   m)  
  {  
  if   (m.Msg   ==   0x00f)  
  {  
  if   (_Paint)  
  base.WndProc(ref   m);  
  else  
  m.Result   =   IntPtr.Zero;  
  }  
  else  
  base.WndProc(ref   m);  
  }  
   
  protected   override   void   OnKeyPress(System.Windows.Forms.KeyPressEventArgs   e)  
  {  
  }  
   
   
  protected   override   void   OnKeyDown(System.Windows.Forms.KeyEventArgs   e)  
  {  
  }  
   
  protected   override   void   OnKeyUp(System.Windows.Forms.KeyEventArgs   e)  
  {  
  }  
   
   
  public   void   ChangeColor_Line()  
  {  
  _Paint   =   false;  
  int   CurrentSelectionStart   =   SelectionStart;  
  int   CurrentSelectionLength   =   SelectionLength;  
   
  int   pos   =   CurrentSelectionStart;  
  while   ((pos   >   0)   &&   (Text[pos   -   1]   !=   '\n'))  
  pos--;  
   
  int   pos2   =   CurrentSelectionStart;  
  while   ((pos2   <   Text.Length)   &&  
  (Text[pos2]   !=   '\n'))  
  pos2++;  
  string   s   =   Text.Substring(pos,   pos2   -   pos);  
   
  Select(pos,   pos2);  
  SelectionColor   =   System.Drawing.Color.Black;  
  Select(pos,   0);  
  System.Collections.ArrayList   arr   =   Html.DrawText(s);  
  if   (arr   !=   null)  
  for   (int   i   =   0;   i   <   arr.Count;   i++)  
  {  
  Select(((Html.ColorText)arr[i]).Index   +   pos,   ((Html.ColorText)arr[i]).Length);  
  SelectionColor   =   ((Html.ColorText)arr[i]).TextColor;  
  }  
  if   (CurrentSelectionStart   >=   0)  
  Select(CurrentSelectionStart,   CurrentSelectionLength);  
  _Paint   =   true;  
  }  
   
  public   void   ChangeColor_All()  
  {  
  _Paint   =   false;  
  int   CurrentSelectionStart   =   SelectionStart;  
  int   CurrentSelectionLength   =   SelectionLength;  
  SelectAll();  
  SelectionColor   =   System.Drawing.Color.Black;  
  Select(0,   0);  
  System.Collections.ArrayList   arr   =   Html.DrawText(Text);  
  if   (arr   !=   null)  
  {  
  Html.ColorText[]   c   =   new   Html.ColorText[arr.Count];  
  arr.CopyTo(c);  
  for   (int   i   =   0;   i   <   c.Length;   i++)  
  {  
  Select(c[i].Index,   c[i].Length);  
  SelectionColor   =   c[i].TextColor;  
  }  
  }  
  if   (CurrentSelectionStart   >=   0)  
  Select(CurrentSelectionStart,   CurrentSelectionLength);  
  _Paint   =   true;  
  }  
   
  protected   override   void   OnTextChanged(EventArgs   e)  
  {  
  ChangeColor_Line();  
  base.OnTextChanged(e);  
  }  
  }  
   
  因为是使用的2005写的,不知道有没有什么关系,应该是没有,^_^Top

2 楼xiandaliu(仙达流,菜鸟先飞)回复于 2005-01-10 09:44:59 得分 0

打开文件使用change_all方法非常的慢Top

3 楼xiandaliu(仙达流,菜鸟先飞)回复于 2005-01-11 09:04:49 得分 0

顶一个Top

4 楼liulxmooo(娃娃)回复于 2005-01-11 09:10:21 得分 0

upTop

5 楼terryshi(terryshi)回复于 2005-01-11 09:26:57 得分 0

freetextbox~~免费Top

6 楼RockyZhang(Rocky)回复于 2005-01-11 09:28:31 得分 45

微软提供的HTML编辑控件.试试这个,还不错.  
  http://windowsforms.net/articles/htmleditor.aspxTop

7 楼owg(OMG)回复于 2005-01-11 09:55:33 得分 10

http://www.evget.com/view/viewCategoryProduct.asp?language=&mode=&productTypeId=&categoryId=9Top

8 楼mooddecode1980(心情解码)回复于 2005-01-11 09:59:02 得分 0

up  
   
   
   
   
   
   
  :)Top

9 楼joelbh(ILoveYou)回复于 2005-01-11 10:47:00 得分 0

freetextbox不错啊Top

10 楼LoveCherry(论成败,人生豪迈;大不了,重头再来!^_^)回复于 2005-01-11 10:51:09 得分 0

upTop

11 楼zhzuo(秋枫)回复于 2005-01-11 12:40:53 得分 45

http://www.windowsforms.net/ControlGallery/default.aspx?Category=13&tabindex=10Top

12 楼3gold(新丁)回复于 2005-01-11 13:03:57 得分 0

FCKedit推荐Top

13 楼xiandaliu(仙达流,菜鸟先飞)回复于 2005-01-11 18:47:49 得分 0

对不起,我没说清楚,是windows的控件Top

相关问题

  • 教教我怎么在ACTIVE X控件文本编辑器接受HTML代码并且显示出来!
  • 请问哪里有免费的文本编辑控件下载!
  • 求一在WEB页面下文本编辑的控件
  • 寻求一个有基本功能的文本编辑控件
  • 求html浏览编辑器控件
  • 有没有HTML的编辑控件
  • 采用unicode编码的文本怎么在编辑控件上显示啊?
  • 有没有既能编辑文本又能插入对象的控件?
  • 横秋扫盲系列(4): CRichEditCtrl 超文本编辑(MSN/QQ常用控件)
  • 如何在单行文本编辑控件中增加enter事件?

关键词

  • ms.net
  • 控件
  • tag
  • html
  • colortext
  • texttype
  • currentselectionstart
  • currentselectionlength
  • textcolor
  • richtextbox

得分解答快速导航

  • 帖主:xiandaliu
  • RockyZhang
  • owg
  • zhzuo

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo