拖放在 C# 中不起作用

Drag and drop not working in C#(拖放在 C# 中不起作用)
本文介绍了拖放在 C# 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 C# 中创建了一个拖放控件,以允许人们将文件拖放到我的表单上.这是我遇到的问题,它在调试时工作正常;但是,在管理员模式下运行我的程序时,它不起作用.这有什么原因吗?

I created a drag and drop control within C# to allow people to drop files onto my form. Here's the problem I'm having, it works fine when it's being debugged; however when running my program in administrator mode it doesn't work. Is there any reason for this?

这是我的代码:

private void panel1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop)) 
        e.Effect = DragDropEffects.Copy;
    else
        e.Effect = DragDropEffects.None;
}

string startDir;

private void panel1_DragDrop(object sender, DragEventArgs e)
{
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    dropZoneLabel.Text = "Adding files; please wait...";
    foreach (string file in files)
    {
        bool isFolder = File.GetAttributes(file).HasFlag(FileAttributes.Directory);
        if (isFolder)
        {
            //Scan the folder for all files
            DirectoryOperations searchFolders = new DirectoryOperations();
            DirectoryInfo di = new DirectoryInfo(file);
            foreach (FileInfo dropfile in searchFolders.FullDirList(di, "*"))
            {
                listBox1.Items.Add(dropfile.Name);
            }
            startDir = di.FullName;
        }
        else
        {
            //It's a file so add it as normal
            listBox1.Items.Add(file);
        }
    }
    dropZoneLabel.Text = "Drop files or folders here";
}

推荐答案

从 Windows Vista 开始,由于用户界面特权隔离,您无法从运行在较低完整性级别的应用程序拖放到运行在较高级别的应用程序.

Starting from Windows Vista because of User Interface Privilege Isolation you cannot drag and drop from an application running at lower integrity level to an application which runs on a higher level.

有关详细信息,请参阅本文:为什么当我的应用程序运行提升时拖放不起作用?

See this article for more details: Why Doesn’t Drag-and-Drop work when my Application is Running Elevated?

这篇关于拖放在 C# 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)