天天看點

關于mapxtreme中畫圓問題(c#)

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();
            }
        }      
上一篇: mapxtreme相關