2
我在C#中創建了一個拖放控件,允許用戶將文件拖放到我的表單上。這是我遇到的問題,它在調試時工作正常;但是,當以管理員模式運行我的程序時,它不起作用。這有什麼理由嗎?拖放不工作在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";
}
謝謝,我用這個現在http://blogs.msdn.com/b/msdnforum/archive/2010/03/30/a-quick-start-guide -of-process-mandatory-level-checking-and-self-elevation-under-uac.aspx?Redirected = true,似乎是一個更好的解決方案。 –