C\#매의 눈 을 만 드 는 상세 한 전 과정(주석 포함)인 스 턴 스 코드
이벤트 응답 을 잘 봐 야 합 니 다.
1.매의 눈 지도 자원 불 러 오기
privatevoid axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
// ,
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
axMapControl2.Extent = axMapControl2.FullExtent;
}
2.매의 눈 사각형 상자 그리 기
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
//
IEnvelope pEnv = (IEnvelope)e.newEnvelope;
IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;
IActiveView pAv = pGra as IActiveView;
// , axMapControl2
pGra.DeleteAllElements();
IRectangleElement pRectangleEle = new RectangleElementClass();
IElement pEle = pRectangleEle as IElement;
pEle.Geometry = pEnv;
//
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 255;
//
ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = 2;
pOutline.Color = pColor;
//
pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 0;
//
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;
pFillShapeEle.Symbol = pFillSymbol;
pGra.AddElement((IElement)pFillShapeEle, 0);
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
3.상호작용 실현
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint pPt=new PointClass ();
pPt.PutCoords (e.mapX ,e.mapY );
//
axMapControl1 .CenterAt (pPt );
}