文本编辑器

first2526 2004-10-30 04:44:10
各位大虾请问:
实现一个带语法显示的文本编辑器,可以对Url进行点击,不知道原理
是用richtextbox还是用其他的控件阿。GDI能用到吗?
说说原理和过程可以吗?如果有示例源码更好了。谢谢阿。
...全文
114 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
first2526 2004-11-01
  • 打赏
  • 举报
回复
这些只能对纯文本进行处理阿。增加一些图标、图片什么的呢?
北京的雾霾天 2004-10-30
  • 打赏
  • 举报
回复
我写了一个高亮代码的小代码段:
private void FormatCode()
{
string[] KeyWords = new string[]{"string", "private", "void", "new", "this", "while", "int"};
for (int i = 0; i<KeyWords.Length; i++)
{
string selectText = KeyWords[i];
int index = this.richTextBox1.Find(selectText, 0 , RichTextBoxFinds.NoHighlight & RichTextBoxFinds.None);;

while (index>=0)
{
this.richTextBox1.SelectionColor = Color.Blue;

System.Drawing.Font currentFont = richTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = FontStyle.Bold; //| FontStyle.Underline;
richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, newFontStyle);

this.richTextBox1.SelectionStart = this.richTextBox1.SelectionStart + this.richTextBox1.SelectionLength;
this.richTextBox1.SelectionLength = 0;
index = this.richTextBox1.Find(selectText, index +1 , RichTextBoxFinds.NoHighlight & RichTextBoxFinds.None);
}
}
}
genius0182 2004-10-30
  • 打赏
  • 举报
回复
实现URL进行点击的代码:
在构造函数中订阅事件:
this.rtfTest.LinkClicked+=new System.Windows.Forms.LinkClickedEventHandler(this.rtfTest_
LinkClick);
事件处理程序:
private void rtfTest_LinkClick(object sender,System.Windows.Forms.LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
张海霖 2004-10-30
  • 打赏
  • 举报
回复
不用gdi,就是代码加亮

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧