Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click License = New esriLicenseObj License.Initialize_ArcInfo() Try 'strPath = "C:\Users\owner\Desktop\gis Dev\parcel.mxd" ' MXD path Dim pMapdoc as ImapDocument = New MapDocument pMapDoc.Open("C:\Users\owner\Desktop\gis Dev\parcel.mxd") 'pActiveView = pMapDocument.PageLayout 'pActiveView.Activate(hWnd) Dim pFeatureLayer As IFeatureLayer = CType(pMapDoc.Layer(0, 0), IFeatureLayer) Dim featureName As String = pFeatureLayer.Name Dim pMap As IMap ''Dim pLayer As ILayer Dim pActiveView As IActiveView pActiveView = pMapDoc.PageLayout pActiveView.Activate(GetDesktopWindow()) '(hWnd) 'Dim pFeatureLayer As IFeatureLayer Dim pFeatureSelection As IFeatureSelection Dim pQueryFilter As IQueryFilter pMap = pMapDoc.Map(0) ' this is the solution pActiveView = pMap pQueryFilter = New QueryFilter ''First layer in the map 'If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub pFeatureLayer = pMap.Layer(0) pFeatureSelection = pFeatureLayer 'QI 'Create the query filter pQueryFilter = New QueryFilter 'pQueryFilter.SubFields = "PROP_ID" pQueryFilter.WhereClause = "PROP_ID = '" & UCase(txtParcel.Text) & "'" Dim pFClass As IFeatureClass = pFeatureLayer.FeatureClass Dim pFCursor As IFeatureCursor = pFClass.Search(pQueryFilter, True) 'Invalidate only the selection cache 'Flag the original selection pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) 'Perform the selection pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False) 'Flag the new selection pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) Dim pFeature As IFeature pFeature = pFCursor.NextFeature Dim nCols As Integer nCols = pFeature.Fields.FieldCount 'define row 'Dim nRows As Integer ''Me.Listsheet.ColumnHeaderCollection = nCols 'nRows = pFeature.Fields.FieldCount For i = 2 To nCols - 1 ' Me.lstResult.Items.Add(pFeature.Fields.Field(i).Name & " " & pFeature.Value(i)) Me.Listsheet.Items.Add(pFeature.Fields.Field(i).Name & " " & pFeature.Value(i)) 'Me.tmpDT.DataSource(pFeature.Fields.Field(i).Name & " " & pFeature.Value(i)) 'convertICursorToDataTable(tmpDT) Next ''Do not make any call to ArcObjects after ShutDownApplication() ' Get the license back to the ArcInfo ' License.ShutDown() ''**************************************************************** Catch ex As Exception MsgBox(ex.ToString) Return End Try '****************************************************************************** End SubSolved! Go to Solution.
pFeature = pFCursor.NextFeature Dim pEnvelope as IEnvelope If Not pFeature Is Nothing Then pEnvelope = pfeature.Extent ' back out a little from the extent of the feature ' comment out or remove next line if not wanted pEnvelope.Expand 0.5, 0.5, False pActiveView.Extent = pEnvelope pActiveView.Refresh End If
Public Class Form1
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Property pMapDoc As IMapDocument
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Try
'Dim strPath As String
'Dim hWnd As Long
'R21160
'strPath = "C:\Users\owner\Desktop\gis Dev\FinalProject\parcel.mxd" ' MXD path
'Dim pMapDoc As IMapDocument = New MapDocument
pMapDoc = New MapDocument
pMapDoc.Open("C:\Users\owner\Desktop\gis Dev\FinalProject\parcel.mxd")
'pActiveView = pMapDocument.PageLayout
'pActiveView.Activate(hWnd)
Dim pFeatureLayer As IFeatureLayer = CType(pMapDoc.Layer(0, 0), IFeatureLayer)
Dim featureName As String = pFeatureLayer.Name
Dim pMap As IMap
''Dim pLayer As ILayer
Dim pActiveView As IActiveView
pActiveView = pMapDoc.PageLayout
pActiveView.Activate(GetDesktopWindow()) '(hWnd)
'Dim pFeatureLayer As IFeatureLayer
Dim pFeatureSelection As IFeatureSelection
Dim pQueryFilter As IQueryFilter
pMap = pMapDoc.Map(0) ' this is the solution
pActiveView = pMap
pQueryFilter = New QueryFilter
''First layer in the map
'If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub
pFeatureLayer = pMap.Layer(0)
pFeatureSelection = pFeatureLayer 'QI
'Create the query filter
pQueryFilter = New QueryFilter
'pQueryFilter.SubFields = "PROP_ID"
pQueryFilter.WhereClause = "PROP_ID = '" & UCase(txtParcel.Text) & "'"
Dim pFClass As IFeatureClass = pFeatureLayer.FeatureClass
Dim pFCursor As IFeatureCursor = pFClass.Search(pQueryFilter, True)
'Invalidate only the selection cache
'Flag the original selection
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
'Perform the selection
pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
'Flag the new selection
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
Dim pFeature As IFeature
' pFeature = pFCursor.NextFeature
pFeature = pFCursor.NextFeature
Dim pEnvelope As IEnvelope
If Not pFeature Is Nothing Then
pEnvelope = pFeature.Extent
' back out a little from the extent of the feature
' comment out or remove next line if not wanted
pEnvelope.Expand(0.5, 0.5, False)
pActiveView.Extent = pEnvelope
pActiveView.Refresh()
End If
Dim nCols As Integer
nCols = pFeature.Fields.FieldCount
For i = 2 To nCols - 1
Me.Listsheet.Items.Add(pFeature.Fields.Field(i).Name & " " & pFeature.Value(i))
Next
' Get the license back to the ArcInfo
' License.ShutDown()
''****************************************************************
Catch ex As Exception
MsgBox(ex.ToString)
Return
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pActiveview As IActiveView
pActiveview = pMapDoc.PageLayout
Dim screenResolution As System.Int32 = 96
Dim outputResolution As System.Int32 = 300
Dim export As IExport = New ExportJPEG
export.Resolution = outputResolution
export.ExportFileName = "C:\Users\owner\Desktop\gis Dev\FinalProject\parcel.jpg"
Dim exportRect As tagRECT
exportRect.left = 0
exportRect.top = 0
exportRect.right = 800 * (outputResolution \ screenResolution)
exportRect.bottom = 800 * (outputResolution \ screenResolution)
Dim envelope As IEnvelope = New EnvelopeClass()
envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom)
export.PixelBounds = envelope
Dim hDC As Int32 = export.StartExporting()
'Dim ActiveView As IActiveView = pMapDoc.ActiveView
pActiveview.Output(hDC, CShort(export.Resolution), exportRect, Nothing, Nothing)
export.FinishExporting()
export.Cleanup()
End Sub
pMap.ClearSelection()