如何在richtext控件里画圆,哪位达人最好给出代码。我是初学者。谢谢!!

解决方案 »

  1.   

    有两种:
    1 圆形是虚拟的,在RichTextBox滚动或刷新或更新后圆形消失
    2 圆形是真实的,它将成为RichTextBox内容的一部分您想要哪种?
      

  2.   

    您可以定义一个数组,该数组用来存储一个或多个坐标(Point)
    然后按照以下步骤来实现
    1 生成一个控件(如Label),并调整相应的属性
    2 在内存中建立一张临时的图像作为画布,使用GDI+等各种绘图,将图像绘制到画布上
    3 将生成的控件Image或BackGroundImage属性值设定为步骤2生成的图像
    4 使用RichTextBox1.Controls.Add方法,将控件添加进去(您可以指定它的坐标)
    5 将当前已经添加的控件的坐标记录在数组中(如对应第1个数据)
    6 添加RichTextBox1.Scroll事件代码,在该代码中,通过获取滚动条的值来计算已添加控件应该所在的位置说明:
    控件可以通过代码生成(推荐)
    该方法与网上流传的QQ聊天窗口内RichTextBox方法不同,属于简单型
    您务必要定义一个数组,用来参与ScrollBar滚动时,将目标控件重新定位
      

  3.   

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
                private Point center;     
                int radius;
                private Graphics g;
                bool dragging;
                private List<drawtype> ls = new List<drawtype>();
                private void Form1_Paint(object sender, PaintEventArgs e)
                {
                    Rectangle rect = new Rectangle(center, Size.Empty);
                    rect.Inflate(radius, radius);
                    e.Graphics.DrawEllipse(Pens.DarkCyan, rect);
                }
                private void Form1_MouseDown(object sender, MouseEventArgs e)
                {
                    center = e.Location;
                    radius = 0;
                    dragging = true;
                }
                private void Form1_MouseMove(object sender, MouseEventArgs e)
                {
                    if (dragging)
                    {
                        Point diff = new Point(e.Location.X - center.X, e.Location.Y - center.Y);
                        radius = (int)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
                        panel1.Invalidate();
                    }
                }            private void Form1_MouseUp(object sender, MouseEventArgs e)
                {
                    dragging = false;
                    panel1.Invalidate();            }            private void Form1_Load(object sender, EventArgs e)
                {
                    this.pictureBox1.MouseDown += panel1_MouseDown;
                    this.pictureBox1.MouseMove += panel1_MouseMove;
                    this.pictureBox1.MouseUp += panel1_MouseUp;
                }        
        }
    }以上是我写的代码,按我的思路,可以给我指出哪里不对吗?谢谢楼上