private bool method_2(IElement ielement_1, out ICallout icallout_0) { icallout_0 = null; try { if (ielement_1 is ITextElement) { ITextElement element = ielement_1 as ITextElement; ITextSymbol symbol = element.Symbol; if (!(symbol is IFormattedTextSymbol)) { return(false); } IFormattedTextSymbol symbol2 = symbol as IFormattedTextSymbol; ITextBackground background = symbol2.Background; if (background == null) { return(false); } if (!(background is ICallout)) { return(false); } icallout_0 = background as ICallout; return(true); } if (ielement_1 is IMarkerElement) { IMarkerElement element2 = ielement_1 as IMarkerElement; IMarkerSymbol symbol3 = element2.Symbol; if (!(symbol3 is IMarkerBackgroundSupport)) { return(false); } IMarkerBackgroundSupport support = symbol3 as IMarkerBackgroundSupport; IMarkerBackground background2 = support.Background; if (background2 == null) { return(false); } if (!(background2 is ICallout)) { return(false); } icallout_0 = background2 as ICallout; return(true); } } catch { } return(false); }
//TextSymbol private void button18_Click(object sender, EventArgs e) { ITextSymbol textSymbol = new TextSymbolClass(); System.Drawing.Font drawFont = new System.Drawing.Font("宋体", 16, FontStyle.Bold); stdole.IFontDisp fontDisp = (stdole.IFontDisp)(new stdole.StdFontClass()); textSymbol.Font = fontDisp; textSymbol.Color = getRGB(0, 255, 0); textSymbol.Size = 20; IPolyline polyline = new PolylineClass(); IPoint point = new PointClass(); point.PutCoords(1, 1); polyline.FromPoint = point; point.PutCoords(10, 10); polyline.ToPoint = point; ITextPath textPath = new BezierTextPathClass(); //创建简单标注 ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = getRGB(255, 0, 0); lineSymbol.Width = 5; ISimpleTextSymbol simpleTextSymbol = textSymbol as ISimpleTextSymbol; simpleTextSymbol.TextPath = textPath; object oLineSymbol = lineSymbol; object oTextSymbol = textSymbol; IActiveView activeView = this.axMapControl1.ActiveView; activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); activeView.ScreenDisplay.SetSymbol(oLineSymbol as ISymbol); activeView.ScreenDisplay.DrawPolyline(polyline as IGeometry); activeView.ScreenDisplay.SetSymbol(oTextSymbol as ISymbol); activeView.ScreenDisplay.DrawText(polyline as IGeometry, "简单标注");; activeView.ScreenDisplay.FinishDrawing(); //创建气泡标注(两中风格,一种是有锚点,一种是marker方式) //锚点方式 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = getRGB(0, 255, 0); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; IBalloonCallout balloonCallout = new BalloonCalloutClass(); balloonCallout.Style = esriBalloonCalloutStyle.esriBCSRectangle; balloonCallout.Symbol = simpleFillSymbol; balloonCallout.LeaderTolerance = 10; point.PutCoords(5, 5); balloonCallout.AnchorPoint = point; IGraphicsContainer graphicsContainer = activeView as IGraphicsContainer; IFormattedTextSymbol formattedTextSymbol = new TextSymbolClass(); formattedTextSymbol.Color = getRGB(0, 0, 255); point.PutCoords(10, 5); ITextBackground textBackground = balloonCallout as ITextBackground; formattedTextSymbol.Background = textBackground; activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); activeView.ScreenDisplay.SetSymbol(formattedTextSymbol as ISymbol); activeView.ScreenDisplay.DrawText(point as IGeometry, "气泡1"); activeView.ScreenDisplay.FinishDrawing(); //marker方式 textSymbol = new TextSymbolClass(); textSymbol.Color = getRGB(255, 0, 0); textSymbol.Angle = 0; textSymbol.RightToLeft = false; textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; IMarkerTextBackground markerTextBackground = new MarkerTextBackgroundClass(); markerTextBackground.ScaleToFit = true; markerTextBackground.TextSymbol = textSymbol; IRgbColor rgbColor = new RgbColorClass(); IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass(); //string fileName = @"E:\vs2005\第五章\lesson2\lesson2\data\qq.bmp"; string path = Directory.GetCurrentDirectory(); string fileName = path + @"\qq.bmp"; pictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName); pictureMarkerSymbol.Angle = 0; pictureMarkerSymbol.BitmapTransparencyColor = rgbColor; pictureMarkerSymbol.Size = 20; pictureMarkerSymbol.XOffset = 0; pictureMarkerSymbol.YOffset = 0; markerTextBackground.Symbol = pictureMarkerSymbol as IMarkerSymbol; formattedTextSymbol = new TextSymbolClass(); formattedTextSymbol.Color = getRGB(255, 0, 0); fontDisp.Size = 10; fontDisp.Bold = true; formattedTextSymbol.Font = fontDisp; point.PutCoords(15, 5); formattedTextSymbol.Background = markerTextBackground; activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); activeView.ScreenDisplay.SetSymbol(formattedTextSymbol as ISymbol); activeView.ScreenDisplay.DrawText(point as IGeometry, "气泡2"); activeView.ScreenDisplay.FinishDrawing(); }