How to drag a file to toccontrol and load it to map (VB. NET source code)

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.