问题描述
我在 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# 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)