Developer Reference ENCX .NET Controls

The ENCX .NET controls make using ENCX from a .NET language easier. You do not have to use these controls but they may prove a useful starting point for your own applications. The C# source code is provided for you to read and adapt.

There are two controls in the ENCXControls project - one to draw raster charts and one to draw S57 charts. There's also a class (GdiHelper) to help convert from a .NET Graphics object to a Windows HDC.

To use the controls, you first need to add them into your .NET project. Here's what to do:

  • Create a new project and open the form view.
  • Add the ENCXControls project to your solution.
  • Add a reference to Interop.ENCX.dll from the bin folder in the library.
  • Build the solution.
  • Select Toolbox from the View menu.
  • Click "My User Controls" on the Toolbox.
  • Right click on the Toolbox and select "Add/Remove Items...".
  • Click Browse to find EncXControls.dll.
  • Your Toolbox now should have RasControl and S57Control.

Drag one (or both) of these onto your Form.

The two controls are very similar to use as the VB.NET code below illustrates. To keep things transparent, the ENCX library, manager and draw instances still need to be created in your code. The user controls simply help in managing the drawing.

Private m_encxlib As ENCX.Library
Private m_rasmgr As ENCX.RasManager
Private WithEvents m_rasdraw As ENCX.RasDraw
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    m_encxlib = New ENCX.Library
    m_encxlib.Construct("", "")
    m_rasmgr = New ENCX.RasManager
    Try
        m_rasmgr.OpenRasFolder(m_encxlib, sRasFolder)
    Catch ex As Exception
        MsgBox("Error opening renc : " + ex.Message)
    End Try
    m_rasdraw = New ENCX.RasDraw
    RasControl1.Init(m_rasdraw, m_encxlib.Dongle())
    RasControl1.SetChart(m_rasmgr, sRAS_CHART_TO_OPEN)
End Sub
Private m_encxlib As ENCX.Library
Private m_s57mgr As ENCX.S57Manager
Private WithEvents m_rasdraw As ENCX.RasDraw
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    m_encxlib = New ENCX.Library
    m_encxlib.Construct("", "")
    m_s57mgr = New ENCX.S57Manager
    Try
        m_s57mgr .OpenSenc(m_encxlib, sSencFolder)
    Catch ex As Exception
        MsgBox("Error opening senc : " + ex.Message)
    End Try
    m_s57draw = New ENCX.S57Draw
    m_s57draw.SetManager(m_s57mgr)
    S57Control.Init(m_s57draw, m_encxlib.Dongle())
End Sub

The controls both provide a PaintOverlaysEvent so that you can easily insert your own code to draw on top of the charts. See Overlays and the ENCX .NET Controls for more information and some sample code.

The sample applications EncView1 and RasView1 use the ENCX .NET controls.