private void tSql_TextChanged(object sender, EventArgs e)
{
int index = this.tSql.SelectionStart; //记录修改的位置
this.tSql.SelectAll();
this.tSql.SelectionColor = Color.Black;
//SQL关键字
//string[] keystr ={ "select ", "from ", "where ", " and ", " or ",
// " order ", " by ", " desc ", " when ", " case ",
// " th

private void tSql_TextChanged(object sender, EventArgs e)

{
int index = this.tSql.SelectionStart; //记录修改的位置
this.tSql.SelectAll();
this.tSql.SelectionColor = Color.Black;
//SQL关键字
//string[] keystr ={ "select ", "from ", "where ", " and ", " or ",
// " order ", " by ", " desc ", " when ", " case ",
// " then ", " end ", " on ", " in ", " is ", " else ",
// " left ", " join ", " not ", " null " };

//C#关键字

string[] keystr =
{
"abstract ", "enum ", "long ", "stackalloc ",
"as ", "event ", "namespace ", "static ",
"base ", "explicit ", "new ", "string ",
"bool ", "extern ", "null ", "struct ",
"break ", "false ", "object ", "switch ",
"byte ", "finally ", "operator ", "this ",
"case ", "fixed ", "out ", "throw ",
"catch ", "for ", "params ", "try ",
"checked ", "foreach ", "private ", "typeof ",
"class ", "goto ", "protected ", "uint ",
"const ", "if ", "public ", "ulong ",
"continue ", "implicit ", "readonly ", "unchecked ",
"decimal ", "in ", "ref ", "unsafe ",
"default ", "int ", "return ", "ushort ",
"delegate ", "interface ", "sbyte ", "using ",
"do ", "internal ", "sealed ", "virtual ",
"double ", "is ", "short ", "void ",
"else ", "lock ", "sizeof ", "while "
};

for (int i = 0; i < keystr.Length; i++)
this.getbunch(keystr[i], this.tSql.Text);

this.tSql.Select(index, 0); //返回修改的位置
this.tSql.SelectionColor = Color.Black;
}

public int getbunch(string p, string s) //给关键字上色

{
int cnt = 0;
int M = p.Length;
int N = s.Length;
char[] ss = s.ToCharArray(), pp = p.ToCharArray();
if (M > N) return 0;
for (int i = 0; i < N - M + 1; i++)

{
int j;
for (j = 0; j < M; j++)

{
if (ss[i + j] != pp[j]) break;
}
if (j == p.Length)

{
this.tSql.Select(i, p.Length);
this.tSql.SelectionColor = Color.Blue;
cnt++;
}
}
return cnt;
}
posted on
2008-04-22 15:53
小角色
阅读(
2754)
评论()
收藏
举报