Drag and drop not working in 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# 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:拖放在 C# 中不起作用
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01