关于mapxtreme中画圆问题(c#)

来源:互联网 发布:台湾人 知乎 编辑:程序博客网 时间:2024/06/05 21:58
mapxtreme有自带的CustomCircleMapTool类。但我想实现的是,当我动态画圆的时候,不光显示一个圆圈。还想显示半径,并标注长度。即显示圆心到鼠标的一条直线。我尝试通过双缓冲的方式来画,但是mapcontrol还是闪的比较厉害。不知道有没有人知道怎么实现?----------------------------        private void circle_Paint(object sender, PaintEventArgs e)        {            if (m_candraw && m_firstPoint.x != -1 && m_firstPoint.y != -1)            {                System.Drawing.Point p1, p2;                p1 = mapToScreen(m_firstPoint);                p2 = mapToScreen(m_secondPoint);                int radius = (int)(Math.Sqrt(Math.Pow(p1.Y - p2.Y, 2) + Math.Pow(p1.X - p2.X,2)));                System.Drawing.Rectangle rect = e.ClipRectangle;                BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;                BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);                Graphics g = myBuffer.Graphics;                Pen pen = new Pen(Color.Blue);                System.Drawing.Font font = new System.Drawing.Font("arial", 9);                Brush brush = new SolidBrush(Color.Blue);                g.Clear(this.BackColor);                System.Drawing.Point point = mapToScreen(m_firstPoint);                rect = new System.Drawing.Rectangle(p1.X - radius, p1.Y - radius, radius * 2, radius * 2);                g.DrawEllipse(pen, rect);                g.DrawLine(pen, p1, p2);                g.DrawString("     "+radius.ToString(), font, brush, p2);                myBuffer.Render(e.Graphics);                pen.Dispose();                font.Dispose();                brush.Dispose();                g.Dispose();                myBuffer.Dispose();            }        }