RichTextBox每行使用不同的文字颜色

private void btnStart_Click(object sender, EventArgs e)
        {
            var shaps = new List<Shape>
            {
                new Rectangle(),
                new Triangle(),
                new Cicrle()
            };

            foreach (Shape s in shaps)
            {
                rtxtDisplay.SelectionStart = rtxtDisplay.Text.Length;

                if (s.Draw().Contains(""))
                {
                    rtxtDisplay.SelectionColor = Color.Red;
                }
                else if (s.Draw().Contains("矩形"))
                {
                    rtxtDisplay.SelectionColor = Color.Green;
                }
                else
                {
                    rtxtDisplay.SelectionColor = Color.Yellow;
                }
                rtxtDisplay.AppendText(s.Draw());
                rtxtDisplay.AppendText(System.Environment.NewLine);
            }
            rtxtDisplay.AppendText(System.Environment.NewLine);
        }

 

posted @ 2024-08-09 11:45  逯文杰  阅读(72)  评论(0编辑  收藏  举报