参考DeskTop帮助文档
准备:添加一个Button控件
Tools—>Customize—>Commands tab—> UIControl—>IButtonControl
在该Button的Click事件中添加以下代码:
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Dim pWorkSpace As IFeatureWorkspace
'Change ‘e:\street’ to the source location of the shapefile you wish to add
Set pWorkSpace = pWorkspaceFactory.OpenFromFile("e:\street", 0)
Dim pClass As IFeatureClass
'Change polygon to the name of the shapefile you wish to add
Set pClass = pWorkSpace.OpenFeatureClass("polygon")
Dim pLayer As IFeatureLayer
Set pLayer = New FeatureLayer
Set pLayer.FeatureClass = pClass
pLayer.Name = pClass.AliasName
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.AddLayer pLayer
pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing
准备:添加一个Button控件
Tools—>Customize—>Commands tab—> UIControl—>IButtonControl
在该Button的Click事件中添加以下代码:
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Dim pWorkSpace As IFeatureWorkspace
'Change ‘e:\street’ to the source location of the shapefile you wish to add
Set pWorkSpace = pWorkspaceFactory.OpenFromFile("e:\street", 0)
Dim pClass As IFeatureClass
'Change polygon to the name of the shapefile you wish to add
Set pClass = pWorkSpace.OpenFeatureClass("polygon")
Dim pLayer As IFeatureLayer
Set pLayer = New FeatureLayer
Set pLayer.FeatureClass = pClass
pLayer.Name = pClass.AliasName
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.AddLayer pLayer
pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing