编程语言
首页 > 编程语言> > 基于c#/Arcgis Engine开发时,从ArcCatalog拖放(DragDrog)数据集至TextBox的实现

基于c#/Arcgis Engine开发时,从ArcCatalog拖放(DragDrog)数据集至TextBox的实现

作者:互联网

原文:http://www.samuelbosch.com/2009/06/drag-drop-from-arccatalog.html

 

帮助类:

  1.   using System.Collections.Generic;
  2.   using System.Windows.Forms;
  3.   using ESRI.ArcGIS.esriSystem;
  4.   using ESRI.ArcGIS.Geodatabase;
  5.   using ESRI.ArcGIS.SystemUI;
  6.    
  7.   namespace GisSolved.DragDrop
  8.   {
  9.   public class EsriDragDrop
  10.   {
  11.   const string DATAOBJECT_ESRINAMES = "ESRI Names";
  12.   public static bool IsValid(IDataObject dataObject)
  13.   {
  14.   return dataObject.GetDataPresent(DATAOBJECT_ESRINAMES) ||
  15.   dataObject.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop);
  16.   }
  17.   public static List<string> GetPaths(IDataObject dataObject)
  18.   {
  19.   List<string> foundPaths = new List<string>();
  20.   IDataObjectHelper dataObjectHelper = new DataObjectHelperClass();
  21.   dataObjectHelper.InternalObject = (object)dataObject;
  22.    
  23.   if (dataObjectHelper.CanGetNames())
  24.   {
  25.   IEnumName enumNames = dataObjectHelper.GetNames();
  26.   IName name;
  27.   while ((name = enumNames.Next()) != null)
  28.   {
  29.   if (name is IDatasetName)
  30.   {
  31.   IDatasetName datasetName = (IDatasetName)name;
  32.   // only accept feature classes and tables
  33.   if (datasetName.Type == esriDatasetType.esriDTFeatureClass ||
  34.   datasetName.Type == esriDatasetType.esriDTTable)
  35.   {
  36.   string path = System.IO.Path.Combine(datasetName.WorkspaceName.PathName, datasetName.Name);
  37.   foundPaths.Add(path);
  38.   }
  39.   // 还可以判断其他的类型
  40.   // else if (name is ...) { }
  41.   }
  42.   }
  43.   }
  44.   else if (dataObjectHelper.CanGetFiles())
  45.   {
  46.   string[] paths = (string[])dataObjectHelper.GetFiles();
  47.   foreach (string path in paths)
  48.   {
  49.   // TODO : Add code here to check if the file path is a valid path
  50.   foundPaths.Add(path);
  51.   }
  52.   }
  53.   return foundPaths;
  54.   }
  55.   }
  56.   }

 

 

TextBox要设置AllowDrag = true,并且设置两个事件:_DragEnter(拖放数据进来时的判断)、_DragDrop(拖放鼠标放开时的事件),代码如下:

 

 

private void TextBoxPath_DragEnter(object sender, DragEventArgs e)
{
 e.Effect = EsriDragDrop.IsValid(e.Data) ? DragDropEffects.All : DragDropEffects.None; // 判断是从Arcgis拖放来的数据才允许
}

 

 

private void TextBoxPath_DragDrop(object sender, DragEventArgs e)
{
 List<string> paths = EsriDragDrop.GetPaths(e.Data); // 获得拖放过来的数据集的路径
}
来自:https://blog.csdn.net/kowity/article/details/79454104

标签:Engine,集至,string,using,dataObjectHelper,path,拖放,name
来源: https://www.cnblogs.com/gisoracle/p/16695255.html