I'm currently designing a simple WinForms UserControl in C# where a user can drag and drop an excel file onto a panel instead of browsing for the file. I have it technically working, but it's very crude.
In short, my code currently looks like this for the DragEnter and DragDrop events on the panel (removed error handling):
private void dragPanel_DragEnter(object sender, DragEventArgs e)
{
var filenames = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (Path.GetExtension(filenames[0]) == ".xlsx") e.Effect = DragDropEffects.All;
else e.Effect = DragDropEffects.None;
}
private void dragPanel_DragDrop(object sender, DragEventArgs e)
{
var filenames = (string[])e.Data.GetData(DataFormats.FileDrop, false);
string filename = filenames[0];
// Do stuff
}
I'm trying to get the Excel icon to show up as I drag the file, but all I can get is this thing:
Anywhere I've looked online (mostly on this forum) has said I need to implement my own custom cursor if I want a specific icon to show up, but I honestly don't believe that. I took screenshots of multiple applications from different companies all using the exact same control (this is just a subset). Note that none of them are even cursors, the icons just follow the cursor:
Windows Explorer:
Google Chrome:
Adobe Acrobat:
Microsoft Edge:
(Same icon, but DragDropEffects are likely set to None)
So my conclusion is there must be a common windows control for this, but where is it? There's no way all of these companies just coincidentally built the exact same design and functionality!
Any help would be appreciated!
Bonus Question: Apparently in Windows 10 you're not allowed to drag-and-drop onto a program that's running as Administrator, however Chrome definitely lets you do this. You can run Chrome as Admin and drag a file onto it without any issue. What magic did Google use to bypass this security feature? I'd like to implement it as well as my control could potentially be used inside a program running as admin.