In AE, toccontrol does not support file dragging and loading. I wrote a class that supports toccontrol file loading. The usage is simple.
First, add the following content to the form load event:
Dim PC as new dragdropfilestoccontrol
PC. dragdropaxtoccontrol = axtoccontrol1
PC. dragdropload ()
You can drag a file to toccontrol, such as SHP, Dem, And pic.
It will be loaded to the map bound to toccontrol.
Add the following to the form close event:
PC. dragdropunload ()
This class inherits from http://www.cnblogs.com/wall/archive/2008/12/31/1366251.html.ArticleDragdropfiles class in,CodeAs follows:
Of course, you can also write the dragdrop class of some other controls to inherit the dragdropfiles class.
Imports ESRI. ArcGIS. Controls
Imports ESRI. ArcGIS. Carto
Imports ESRI. ArcGIS. esrisystem
''' <Summary>
'''Toccontrol: drag a file class
''' </Summary>
''' <Remarks> </remarks>
Public class dragdropfilestoccontrol
Inherits dragdropfiles
Private m_axtoccontrol as axtoccontrol
''' <Summary>
'''Axtoccontrol
''' </Summary>
''' <Value> </value>
''' <Remarks> </remarks>
Writeonly property dragdropaxtoccontrol () as axtoccontrol
Set (byval value as axtoccontrol)
M_axtoccontrol = Value
End set
End Property
''' <Summary>
''' Load and drag
''' </Summary>
''' <Remarks> </remarks>
Public overrides sub dragdropload ()
If m_axtoccontrol is nothing then
MessageBox. Show ("the layer list control is blank! "," Prompt ", messageboxbuttons. OK)
Exit sub
End if
If m_axtoccontrol.buddy is nothing then
MessageBox. Show ("the layer list control is not bound with a map control! "," Prompt ", messageboxbuttons. OK)
Exit sub
End if
Me. dragdrophwnd = m_axtoccontrol.handle
Mybase. dragdropload ()
End sub
''' <Summary>
''' Inherited functions
''' </Summary>
''' <Param name = "hdrop"> </param>
''' <Remarks> </remarks>
Protected overrides sub dropfiles (byval hdrop as long)
Mybase. dropfiles (hdrop)
Adddraglayerstomap (dragdropfiles, m_axtoccontrol.buddy)
End sub
''' <Summary>
''' Add the file to the map.
''' </Summary>
''' <Param name = "pfilepaths"> </param>
''' <Param name = "pmapcontrol"> </param>
''' <Remarks> </remarks>
Private sub adddraglayerstomap (byval pfilepaths as List (of string), byval pmapcontrol as imapcontrol2)
Pmapcontrol. mousepointer = esricontrolsmousepointer. esripointerhourglass
For I as integer = 0 to pfilepaths. Count-1
If pmapcontrol. checkmxfile (pfilepaths (I) then
Pmapcontrol. loadmxfile (pfilepaths (I ))
Else
Pmapcontrol. Map. addlayer (createlayerfrompath (pfilepaths (I )))
End if
Next
Pmapcontrol. mousepointer = esricontrolsmousepointer. esripointerdefault
End sub
''' <Summary>
''' Creates a layer based on the file path.
''' </Summary>
''' <Param name = "pfilepath"> full file path </param>
''' <Returns> returns the created layer </returns>
''' <Remarks> </remarks>
Private function createlayerfrompath (byval pfilepath as string) as ilayer
Try
Dim playerfactoryhelper as ilayerfactoryhelper
Playerfactoryhelper = new layerfactoryhelper
Dim pfilename as ifilename = new filename
Pfilename. Path = pfilepath
Dim penumlayer as ienumlayer
Penumlayer = playerfactoryhelper. createlayersfromname (pfilename)
Penumlayer. Reset ()
Dim player as ilayer
Player = penumlayer. Next
Dim prelayer as ilayer = nothing
Do while not player is nothing
Prelayer = player
Player = penumlayer. Next
Loop
Return prelayer
Catch ex as exception
Return nothing
End try
End Function
End Class