TatukGIS menu

Knowledge Base

KB10724 - Add a custom text and graphic to map printouts and exported images.

The easiest method is to create a custom layer and do such drawing on the OnPaintLayer event.

VB.NET ActiveX code:

Private WithEvents EventLayer As TatukGIS_DK.XGIS_LayerVectorProcedure

Private Sub Form1_Load(ByVal eventSender As System.Object, _
   ByVal eventArgs As System.EventArgs) Handles MyBase.Load

   Dim lv As TatukGIS_DK.XGIS_LayerVector

   GIS.Open( "myproject.ttkgp"

   lv = New TatukGIS_DK.XGIS_LayerVector
   lv.Name = "myInternalLayer"
   lv.Extent = GIS.Extent

   EventLayer = lv

End Sub

Private Sub eventlayer_OnPaintLayer(ByRef translated As Boolean, ByVal Layer As Object) Handles EventLayer.OnPaintLayer

   Dim gr As Graphics
   Dim pt As TatukGIS_DK.XPoint
   Dim msr As SizeF

   gr = Graphics.FromHdc(IntPtr.op_Explicit(GIS.HDC))

   ' Create font and brush.
   Dim drawFont As New Font("Arial", 16)
   Dim drawBrush As New SolidBrush(Color.Black)

   ' Draw string int the bottomp-right corner
   pt = GIS.MapToScreen(GisUtils.GisPoint(EventLayer.Extent.XMax, EventLayer.Extent.YMin))
   msr = gr.MeasureString("Sample Text", drawFont)
   gr.DrawString("Sample Text", drawFont, drawBrush, Math.Round(pt.X - msr.Width), Math.Round(pt.Y - msr.Height))

   gr = Nothing
   translated = True
End Sub

Created: October 24, 2006, Modified: September 23, 2015