dear all
I am using AxMap as a .Net forms application. I cannot cast AxMapWinGIS.AxMap to MapWindow.Interfaces.IMapWin. How can I get a handle to an IMapWin object from AxMap?
the error is the following:
Nullreferenceexception was unhandled
Object reference not set to an instance of an object.
With the App is possible to add the grid to the map and legend, then with the grids in the map I click in a button to open a new window for map calculation (the code bellow is for the new window "MapCalc"). But gives an error in a line that tries to read what I have in the map.
For Each lay In mMap.Layers
this is the code to open the window .
this is the code of the window (for calculating)Code:Private mapWin As MapWindow.Interfaces.IMapWin Private Sub btnloadmapcalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloadmapcalc.Click Dim NewMapCalc As MapCalc = New MapCalc(mapWin) NewMapCalc.ShowDialog() End Sub
Code:Imports System.IO Imports System.Drawing.Design Imports System.Windows.Forms.Design Imports System.Windows.Forms Imports MapWindow.Interfaces Imports MapWinGIS Public Class MapCalc 'MAP CALCULATOR CODE Inherits System.Windows.Forms.Form Implements MapWinGIS.ICallback Public Sub New(ByRef AxMap1 As IMapWin) InitializeComponent() mMap = AxMap1 updateGridList() End Sub Dim mMap As IMapWin Dim grdName As New List(Of String) Dim grdFileName As New List(Of String) Dim grdHn As New List(Of Integer) Dim usedGrdHn As New List(Of Integer) Dim grdIsFactor As New List(Of Boolean) Dim nUsedGrd As Integer Dim pre As String Dim formulaContainsGrids As Boolean = False Public Sub myError(ByVal KeyOfSender As String, ByVal ErrorMsg As String) Implements MapWinGIS.ICallback.Error End Sub Public Sub Progress(ByVal KeyOfSender As String, ByVal Percent As Integer, ByVal Message As String) Implements MapWinGIS.ICallback.Progress ToolStripProgressBar1.Value = Percent ToolStripStatus.Text = Message End Sub Private Sub updateGridList() formulaContainsGrids = False Me.ListBox3.Items.Clear() grdName.Clear() grdFileName.Clear() grdHn.Clear() usedGrdHn.Clear() Dim lay As Layer For Each lay In mMap.Layers If (lay.LayerType = eLayerType.Grid) Then grdName.Add(lay.Name) grdFileName.Add(lay.FileName) grdHn.Add(lay.Handle) usedGrdHn.Add(-1) 'put layer name on mask Me.ListBox3.Items.Add(lay.Name) End If Next End Sub Private Sub addStringInFormula(ByVal s As String) Dim formulaTxt As String Dim beforeS As String = "" Dim afterS As String = "" formulaTxt = Me.TextBox3.Text If (Me.TextBox3.SelectionLength > 0) Then beforeS = formulaTxt.Substring(0, Me.TextBox3.SelectionStart) afterS = formulaTxt.Substring(Me.TextBox3.SelectionStart + Me.TextBox3.SelectionLength) formulaTxt = beforeS + s + afterS Else formulaTxt = formulaTxt + " " + s End If Me.TextBox3.Text = formulaTxt End Sub End Class


Reply With Quote