关键字高亮插件

weng2961389 2011-07-17 06:14:48
有没有一种插件可以实现,像sql查询分析器样,遇到关键字就自动变色高亮的呢,我想要的是可以自己定义要变色的关键字。。。
...全文
160 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-07-17
  • 打赏
  • 举报
回复
不过要宽的 其他编辑有change事件么?大概就是这个思路
子夜__ 2011-07-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 weng2961389 的回复:]

引用 5 楼 wxr0323 的回复:

ht.Add("select", Color.Blue);
ht.Add("insert", Color.Blue);
ht.Add("in", Color.Blue);
ht.Add("from", Color.Blue);
ht.Add("where", Color.Blue);
……
Web项目好像没RichTextBox控件的啊
……
[/Quote]
textbox不是一样吗?
weng2961389 2011-07-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wxr0323 的回复:]

ht.Add("select", Color.Blue);
ht.Add("insert", Color.Blue);
ht.Add("in", Color.Blue);
ht.Add("from", Color.Blue);
ht.Add("where", Color.Blue);
……
[/Quote]Web项目好像没RichTextBox控件的啊
子夜__ 2011-07-17
  • 打赏
  • 举报
回复
ht.Add("select", Color.Blue);
ht.Add("insert", Color.Blue);
ht.Add("in", Color.Blue);
ht.Add("from", Color.Blue);
ht.Add("where", Color.Blue);
ht.Add("left", Color.DeepPink);
ht.Add("join", Color.Blue);
ht.Add("*", Color.Gray);

可以定义成枚举。
子夜__ 2011-07-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 weng2961389 的回复:]

引用 1 楼 dalmeeme 的回复:

这个试试,可以在ini文件中添加需要高亮的关键字。

插件
我要的是在Web项目中实现的,而且是完全自动检测关键字,然后高亮显示的,这个貌似不行啊
[/Quote]
需要算法
没有这种插件
下面是我以前做的查询分析变色。
WINFORM的 都一样
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace SQLAnalysis
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

public static Hashtable ht = new Hashtable();

private void Form2_Load(object sender, EventArgs e)
{
ht.Add("select", Color.Blue);
ht.Add("insert", Color.Blue);
ht.Add("in", Color.Blue);
ht.Add("from", Color.Blue);
ht.Add("where", Color.Blue);
ht.Add("left", Color.DeepPink);
ht.Add("join", Color.Blue);
ht.Add("*", Color.Gray);
}

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (this.richTextBox1.Text.Trim().Length > 0)
{
int index = this.richTextBox1.SelectionStart;
Change(index);
richTextBox1.Select(index, 0);
richTextBox1.SelectionColor = Color.Black;
}
}

private void Change(int i)
{
int index = i;
bool IsNull = IsKong(index);
int start = GetWordStart(index);
int end = GetWordEnd(index);
richTextBox1.Select(start, end - start);
string word = richTextBox1.SelectedText;

if (ht[word] != null)
{
Color c = (Color)ht[word];
richTextBox1.SelectionColor = c;
}
else
{
richTextBox1.SelectionColor = Color.Black;
}
if (IsNull)
{
index = index - 1;
Change(index);
}
}

private int GetWordStart(int end)
{
int temp = end;
while (temp > 0)
{
temp = temp - 1;
if (richTextBox1.Text[temp] == ' ' || richTextBox1.Text[temp] == '\n')
{
return temp + 1;
}
}
return 0;
}

private int GetWordEnd(int start)
{
int temp = start;
while (temp < richTextBox1.Text.Length)
{

if (richTextBox1.Text[temp] == ' ')
{
return temp;
}
temp = temp + 1;
}
return richTextBox1.Text.Length;
}

private bool IsKong(int index)
{
int temp = index;
richTextBox1.Select(index - 1, 1);
return richTextBox1.SelectedText == " " ? true : false;
}
}
}
weng2961389 2011-07-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dalmeeme 的回复:]

这个试试,可以在ini文件中添加需要高亮的关键字。

插件
[/Quote]我要的是在Web项目中实现的,而且是完全自动检测关键字,然后高亮显示的,这个貌似不行啊
dalmeeme 2011-07-17
  • 打赏
  • 举报
回复
找错了,上面那个不行,不是在程序中用的。
找不到的话自己写个吧,应该不难的。
dalmeeme 2011-07-17
  • 打赏
  • 举报
回复
这个试试,可以在ini文件中添加需要高亮的关键字。

插件

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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