c# - 拖放在 C# 中不起作用

标签 c# .net drag-and-drop admin

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

这是我的代码:

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 开始,由于用户界面特权隔离,您无法从以较低完整性级别运行的应用程序拖放到以较高完整性级别运行的应用程序。

查看这篇文章了解更多详情:Why Doesn’t Drag-and-Drop work when my Application is Running Elevated?

关于c# - 拖放在 C# 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21651580/

相关文章:

java - 将 JLabel 拖到 JFrame 之外

c# - TreeView 。美国各州和城市

c# - .NET Core 2.x 加载引用程序集,代码中没有类型引用

c# - int num = new int();当这条线执行时会发生什么?

.net - 如何使用 RDLC 在 PDF 中嵌入字体

java - 使用 DnD 在 JPanel 中移动和重新排序 JLabel

swift - NSCollectionView 动画重新布局

c# - 绑定(bind)中的属性 setter 调用了两次

c# - 使用 .Toarray 方法后在通用列表上排序

c# - MySqlException (0x80004005) : There is already an open DataReader associated with this Connection which must be closed first