窗体的paint事件中有如下代码;
 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            this.GraphicsText1(richTextBox1,50,50);
            this.GraphicsText2(richTextBox2,50,50);
        }

解决方案 »

  1.   

    你的方框在哪画的,form上还richedit上,代码怎么写的
      

  2.   

    我的方框是在richtextbox中画的
    代码如下:
      private void GraphicsText2(RichTextBox rich,int width,int height)
            {
                if (rich.Text.Length > 0)
                {
                    for (int i = 0; i < rich.Text.Length; i += 2)
                    {
                        Point pt = rich.GetPositionFromCharIndex(i);
                        Graphics g = rich.CreateGraphics();//画板
                        g.DrawRectangle(new Pen(Color.Red, 3), pt.X - 6, pt.Y + 9, width , height );
                    }
                }
            }
    private void Form1_Paint(object sender, PaintEventArgs e)
            {
                this.GraphicsText1(richTextBox1,50,50);
                this.GraphicsText2(richTextBox2,50,50);
            }