DrawShape draws the supplied geometry onto the display. Use the DrawShape method within the esriViewForeground phase of the IMapControlEvents2::OnAfterDraw event.
FlashShape flashes the supplied geometry onto the display.
DrawShape 方法只支持以下对象,而Line等对象不被支持
Geometry objects implementing IEnvelope, IMultiPatch, IMultiPoint, IPoint, IPolygon and IPolyline are supported
public partial class Form1 : Form { ILine m_line; public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1) { IPoint fromPoint = new PointClass(); fromPoint.PutCoords(100, 100); IPoint toPoint = new PointClass(); toPoint.PutCoords(150, 150); ILine line = new LineClass(); line.PutCoords(fromPoint, toPoint); Console.WriteLine(line.Length.ToString()); m_line = line; axMapControl1.FullExtent = line.Envelope; IEnvelope pRect = new EnvelopeClass(); pRect = axMapControl1.Extent; pRect.Expand(2, 2, true); axMapControl1.Extent = pRect; axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing); } if (e.button == 2) { axMapControl1.Extent = axMapControl1.TrackRectangle(); }
}
private IRgbColor GetRGBColor(int red, int green, int blue) { //Create rgb color and grab hold of the IRGBColor interface IRgbColor rGB = new RgbColorClass(); //Set rgb color properties rGB.Red = red; rGB.Green = green; rGB.Blue = blue; rGB.UseWindowsDithering = true; return rGB; }
private void axMapControl1_OnAfterDraw(object sender, IMapControlEvents2_OnAfterDrawEvent e) { if (e.viewDrawPhase == (int)esriViewDrawPhase.esriViewForeground & m_line != null) { ILineSymbol lineSymbol = new SimpleLineSymbolClass(); //Set line symbol properties lineSymbol.Color = GetRGBColor(0, 0, 0); lineSymbol.Width = 2; object oLineSymbol = lineSymbol; IPolyline m_Polyline = new PolylineClass(); ISegmentCollection pSeg = m_Polyline as ISegmentCollection; object Missing = Type.Missing; pSeg.AddSegment((ISegment)m_line, ref Missing, ref Missing); axMapControl1.DrawShape(m_Polyline, ref oLineSymbol); }
} }
|