public static ITextSymbol makeTextSymbol(string fontName, int fontSize) { ITextSymbol textSymbol = new TextSymbolClass(); System.Drawing.Font drawFont = new System.Drawing.Font(fontName, fontSize, FontStyle.Bold); textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(drawFont); textSymbol.Color = GetRGBColor(0, 0, 0); ITextPath textPath = new BezierTextPathClass(); //to spline the text ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol)textSymbol; simpleTextSymbol.TextPath = textPath; return(textSymbol); }
private void axMapControl1_OnAfterDraw(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent e) { //If foreground refreshed if (e.viewDrawPhase == (int)esriViewDrawPhase.esriViewForeground) { //If a line object for splining text exists if (m_Polyline != null) { //Ensure there's at least two points in the line if (m_PointCollection.PointCount > 1) { //Create a line symbol and grab hold of the ILineSymbol interface ILineSymbol lineSymbol = new SimpleLineSymbolClass(); //Set line symbol properties lineSymbol.Color = GetRGBColor(0, 0, 0); lineSymbol.Width = 2; //Create a text symbol and grab hold of the ITextSymbol interface ITextSymbol textSymbol = new TextSymbolClass(); //Create a system drawing font symbol with the specified properties System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16, FontStyle.Bold); //Set the text symbol font by getting the IFontDisp interface textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(drawFont); textSymbol.Color = GetRGBColor(0, 0, 0); //Create a text path and grab hold of the ITextPath interface ITextPath textPath = new BezierTextPathClass(); //to spline the text //Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol)textSymbol; //Set the text path of the simple text symbol simpleTextSymbol.TextPath = textPath; //Draw the line object and spline the user text around the line object oLineSymbol = lineSymbol; object oTextSymbol = textSymbol; axMapControl1.DrawShape(m_Polyline, ref oLineSymbol); axMapControl1.DrawText(m_Polyline, Text1.Text, ref oTextSymbol); } } } }
private void axMapControl1_OnAfterDraw(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent e) { //If foreground refreshed if (e.viewDrawPhase == (int) esriViewDrawPhase.esriViewForeground) { //If a line object for splining text exists if (m_Polyline != null) { //Ensure there's at least two points in the line if (m_PointCollection.PointCount > 1) { //Create a line symbol and grab hold of the ILineSymbol interface ILineSymbol lineSymbol = new SimpleLineSymbolClass(); //Set line symbol properties lineSymbol.Color = GetRGBColor(0, 0, 0); lineSymbol.Width = 2; //Create a text symbol and grab hold of the ITextSymbol interface ITextSymbol textSymbol = new TextSymbolClass(); //Create a system drawing font symbol with the specified properties System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16, FontStyle.Bold); //Set the text symbol font by getting the IFontDisp interface textSymbol.Font = (stdole.IFontDisp) OLE.GetIFontDispFromFont(drawFont); textSymbol.Color = GetRGBColor(0, 0, 0); //Create a text path and grab hold of the ITextPath interface ITextPath textPath = new BezierTextPathClass(); //to spline the text //Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol) textSymbol; //Set the text path of the simple text symbol simpleTextSymbol.TextPath = textPath; //Draw the line object and spline the user text around the line object oLineSymbol = lineSymbol; object oTextSymbol = textSymbol; axMapControl1.DrawShape(m_Polyline, ref oLineSymbol); axMapControl1.DrawText(m_Polyline, Text1.Text, ref oTextSymbol); } } } }
//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(); }