基于c#/Arcgis Engine开发时,从ArcCatalog拖放(DragDrog)数据集至TextBox的实现
2022/9/16 1:18:33
本文主要是介绍基于c#/Arcgis Engine开发时,从ArcCatalog拖放(DragDrog)数据集至TextBox的实现,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
原文:http://www.samuelbosch.com/2009/06/drag-drop-from-arccatalog.html
帮助类:
- using System.Collections.Generic;
- using System.Windows.Forms;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.SystemUI;
- namespace GisSolved.DragDrop
- {
- public class EsriDragDrop
- {
- const string DATAOBJECT_ESRINAMES = "ESRI Names";
- public static bool IsValid(IDataObject dataObject)
- {
- return dataObject.GetDataPresent(DATAOBJECT_ESRINAMES) ||
- dataObject.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop);
- }
- public static List<string> GetPaths(IDataObject dataObject)
- {
- List<string> foundPaths = new List<string>();
- IDataObjectHelper dataObjectHelper = new DataObjectHelperClass();
- dataObjectHelper.InternalObject = (object)dataObject;
- if (dataObjectHelper.CanGetNames())
- {
- IEnumName enumNames = dataObjectHelper.GetNames();
- IName name;
- while ((name = enumNames.Next()) != null)
- {
- if (name is IDatasetName)
- {
- IDatasetName datasetName = (IDatasetName)name;
- // only accept feature classes and tables
- if (datasetName.Type == esriDatasetType.esriDTFeatureClass ||
- datasetName.Type == esriDatasetType.esriDTTable)
- {
- string path = System.IO.Path.Combine(datasetName.WorkspaceName.PathName, datasetName.Name);
- foundPaths.Add(path);
- }
- // 还可以判断其他的类型
- // else if (name is ...) { }
- }
- }
- }
- else if (dataObjectHelper.CanGetFiles())
- {
- string[] paths = (string[])dataObjectHelper.GetFiles();
- foreach (string path in paths)
- {
- // TODO : Add code here to check if the file path is a valid path
- foundPaths.Add(path);
- }
- }
- return foundPaths;
- }
- }
- }
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
这篇关于基于c#/Arcgis Engine开发时,从ArcCatalog拖放(DragDrog)数据集至TextBox的实现的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-12-06使用Microsoft.Extensions.AI在.NET中生成嵌入向量
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#