AE建立氣泡式的提示框(VB.Net和C#源碼)

來源:互聯網
上載者:User
 下面是用AE建立氣泡式提示框的方法:
  
 1、VB.Net源碼

  ''' <summary>
  ''' 建立文本提示框
  ''' </summary>
  ''' <param name="x">提示框標識的位置X座標</param>
  ''' <param name="y">提示框標識的位置Y座標</param>
  ''' <param name="pTextString">提示框中顯示的文本</param>
  ''' <param name="pPoint">提示框箭頭指向的點</param>
  ''' <param name="pGraphicsContainer">包含提示框的graphicscontainer</param>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Function CreateTextElement(ByVal x As Double, ByVal y As Double, ByVal pTextString As String, Optional ByVal pPoint As IPoint = Nothing, Optional ByVal pGraphicsContainer As IGraphicsContainer = Nothing) As IElement
    Dim pElement As IElement = New MarkerElementClass()
    Dim pTElement As IElement = New TextElementClass()
    Dim pTextSymbol As IFormattedTextSymbol = New TextSymbolClass()
    Dim pBalloonCallout As IBalloonCallout = CreateBalloonCallout(x, y)
    Dim pColor As IRgbColor = New RgbColorClass()
    pColor.Red = 150
    pColor.Green = 0
    pColor.Blue = 0
    pTextSymbol.Color = pColor
    Dim pTextBackground As ITextBackground
    pTextBackground = pBalloonCallout
    pTextSymbol.Background = pTextBackground
    pTextSymbol.Size = 8
    CType(pTElement, ITextElement).Symbol = pTextSymbol
    CType(pTElement, ITextElement).Text = pTextString
    If pPoint Is Nothing Then pPoint = New Point : pPoint.PutCoords(x + Const_Dis, y + Const_Dis)
    pTElement.Geometry = pPoint
    pGraphicsContainer.AddElement(pTElement, 1)
    Return pTElement
  End Function

  ''' <summary>
  ''' 建立balloon型提示框
  ''' </summary>
  ''' <param name="x">提示框所在位置X座標</param>
  ''' <param name="y">提示框所在位置Y座標</param>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Function CreateBalloonCallout(ByVal x As Double, ByVal y As Double) As IBalloonCallout
    Dim pRgbClr As IRgbColor = New RgbColorClass()
    pRgbClr.Red = 255
    pRgbClr.Blue = 255
    pRgbClr.Green = 255
    Dim pSmplFill As ISimpleFillSymbol = New SimpleFillSymbolClass()
    pSmplFill.Color = pRgbClr
    pSmplFill.Style = esriSimpleFillStyle.esriSFSSolid
    Dim pBllnCallout As IBalloonCallout = New BalloonCalloutClass()
    pBllnCallout.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle
    pBllnCallout.Symbol = pSmplFill
    pBllnCallout.LeaderTolerance = 1
    Dim pPoint As IPoint = New ESRI.ArcGIS.Geometry.PointClass()
    pPoint.X = x
    pPoint.Y = y
    pBllnCallout.AnchorPoint = pPoint
    Return pBllnCallout
  End Function

  2、C#源碼
 
       public void CreateTextElment(double x, double y)
        {
            IPoint pPoint = new PointClass();
            IMap pMap = axMapControl1.Map;
            IActiveView pActiveView = pMap as IActiveView;
            IGraphicsContainer pGraphicsContainer;
            IElement pElement = new MarkerElementClass();
            IElement pTElement = new TextElementClass();
            pGraphicsContainer = (IGraphicsContainer)pActiveView;
            IFormattedTextSymbol pTextSymbol = new TextSymbolClass();
            IBalloonCallout pBalloonCallout = CreateBalloonCallout(x, y);
            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 150;
            pColor.Green = 0;
            pColor.Blue = 0;
            pTextSymbol.Color = pColor;
            ITextBackground pTextBackground;
            pTextBackground = (ITextBackground)pBalloonCallout;
            pTextSymbol.Background = pTextBackground;
            ((ITextElement)pTElement).Symbol = pTextSymbol;
            ((ITextElement)pTElement).Text = "測試";
            pPoint.X = x + 42;
            pPoint.Y = y + 42;
            pTElement.Geometry = pPoint;
            pGraphicsContainer.AddElement(pTElement, 1);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
       
        public IBalloonCallout CreateBalloonCallout(double x, double y)
        {
            IRgbColor pRgbClr = new RgbColorClass();
            pRgbClr.Red = 255;
            pRgbClr.Blue = 255;
            pRgbClr.Green = 255;
            ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass();
            pSmplFill.Color = pRgbClr;
            pSmplFill.Style = esriSimpleFillStyle.esriSFSSolid;
            IBalloonCallout pBllnCallout = new BalloonCalloutClass();
            pBllnCallout.Style = esriBalloonCalloutStyle.esriBCSRectangle;
            pBllnCallout.Symbol = pSmplFill;
            pBllnCallout.LeaderTolerance = 1;
            IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
            pPoint.X = x;
            pPoint.Y = y;
            pBllnCallout.AnchorPoint = pPoint;
            return pBllnCallout;
        }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.