c# - Drag Files Directly Onto Form Not Control -
is possible drag files directly onto windows form or have onto control on windows form? have been using below code quite time, requires drag onto listview
public form1() { initializecomponent(); this.load += new eventhandler(form1_load); } void form1_load(object sender, eventargs e) { this.listview1.allowdrop = true; this.listview1.columns.add("file name"); this.listview1.dock = dockstyle.fill; this.listview1.smallimagelist = this.imagelist1; this.listview1.view = view.details; this.listview1.dragenter += new drageventhandler(listview1_dragenter); this.listview1.dragdrop += new drageventhandler(listview1_dragdrop); } void listview1_dragenter(object sender, drageventargs e) { if (e.data.getdatapresent("filedrop") && (e.allowedeffect & dragdropeffects.copy) == dragdropeffects.copy) { e.effect = dragdropeffects.copy; } } void listview1_dragdrop(object sender, drageventargs e) { if (e.data.getdatapresent("filedrop") && (e.allowedeffect & dragdropeffects.copy) == dragdropeffects.copy) { string[] filepaths = (string[])e.data.getdata("filedrop"); listviewitem[] items = new listviewitem[filepaths.length]; string filepath; (int index = 0; index < filepaths.length; index++) { filepath = filepaths[index]; if (!this.imagelist1.images.keys.contains(filepath)) { this.imagelist1.images.add(filepath, icon.extractassociatedicon(filepath)); } items[index] = new listviewitem(filepath, filepath); } this.listview1.items.addrange(items); } }
this.dragdrop += new drageventhandler(form_dragdrop);