Problems with drawing rectangle within Graphics...

Topics: Windows Forms
May 14, 2012 at 10:50 AM


Suppose I have following code:

      private void GMapControlMouseDown(object sender, MouseEventArgs e)
            if (e.Button == MouseButtons.Right) return;
            _rectangleGraphicsObj = gMapControl.CreateGraphics();
            _upperLeftPosition = PointToClient(Cursor.Position);

        private void GMapControlMouseUp(object sender, MouseEventArgs e)
            if (e.Button == MouseButtons.Right) return;

            var point = PointToClient(Cursor.Position);
            _myRectangle = new Rectangle(_upperLeftPosition,
                                         new Size(Math.Abs(point.X - _upperLeftPosition.X),
                                                  Math.Abs(point.Y - _upperLeftPosition.Y)));

            Pen myPen = new Pen(Color.Blue, 2);
            _rectangleGraphicsObj.DrawRectangle(myPen, _myRectangle);

So, I want to draw some rectangle on the control, but as a result it just blinks and disappear.

How can I draw rectangle on GMap control? Should I use provided GMapOverlay and GMapPolygon?

Thanks in advance.

May 14, 2012 at 11:14 AM

hold alt and left mouse and drag

May 14, 2012 at 12:47 PM
Edited May 14, 2012 at 12:55 PM

Thank you very much. But how can I get, for example, coordinates of this rectangle?

Update. I found -- SelectedArea property.