用RichTextBox实现字符串中指定字符(汉字)的颜色改变

 private void Form1_Load(object sender, EventArgs e)
 {
            string s = "aaa。bbb‘’中a国";
            ArrayList arr = Validation(s);
            richTextBox1.Text = s;
           
            for (int i = 0; i < arr.Count; i++)
            { 
                richTextBox1.Select((int)arr[i], 1);
                richTextBox1.SelectionColor = Color.Red;
             }
 }

        private  int GetCharASCII(char c)
        {
            return (int)c;
        }
        private  ArrayList  Validation(string s)
        {
            char[] charArray = s.ToCharArray();
            ArrayList intArr = new ArrayList();
            for (int i = 0; i < s.Length; i++)
            {
                char c = charArray[i];
                if (GetCharASCII(c) > 127)
                {
                    intArr.Add(i);
                }
            }
            return intArr;
           
        }

posted on 2006-08-22 17:22  破茧化蝶  阅读(1675)  评论(0编辑  收藏  举报

导航