Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by chezwaldo · Jul 01, 2016 at 07:19 AM · drag and drop

Reason why IDataObject.GetData from System.Windows.Forms returning empty string[] on a drag and drop event

I'm trying to make it so users can add their own textures to a program I'm making and I'm doing it but creating a Windows Form that'll receive a drag and drop event and send that data back in. Here's a stripped down version of the code.

using System.Windows.Forms; public class DragAndDrop : MonoBehaviour { Form DropForm; void Start() { }

 public void ShowDropDialog()
 {
     print("starting window");
     DropForm = new DragDropForm();
     DropForm.ShowDialog();
 }

 class DragDropForm : Form
 {
     public DragDropForm()
     {
         this.AllowDrop = true;
         this.Width = 300;
         this.Height = 300;
         this.Text = "Drag Images here";
         this.DragDrop += new DragEventHandler(this.DragDropForm_DragDrop);
         this.DragEnter += new DragEventHandler(this.DragDropForm_DragEnter);
     }

     void DragDropForm_DragEnter(object sender, DragEventArgs e)
     {
         if (e.Data.GetDataPresent(DataFormats.FileDrop))
         {
             e.Effect = DragDropEffects.Link;
             this.BackColor = System.Drawing.Color.Blue;
         }
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string file in files)
         {
         }
     }
     void DragDropForm_DragDrop(object sender, DragEventArgs e)
     {
         print("dropped");
         object data = e.Data.GetData(DataFormats.FileDrop);
         this.BackColor = System.Drawing.Color.Green;
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string file in files)
         {
         }
         print("closing");
         this.Close();
     }
 }

}

The problems are the Drop event doesn't fire at all, hovering with a dragged file gives the crossed out circle like it doesn't let me drop it, and the e.Data.GetData only returns an empty string instead of a filepath. It really frustrating as I have no idea if I'm doing something wrong.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is it possible to drag a file from the desktop into a desktop application 2 Answers

NGUI Mouse position doesn't match with dragged object 0 Answers

Jigsaw Drag and Drop Game? Help! 0 Answers

How to make my cards dragable in my solitaire game? 1 Answer

Clickable AND draggable object 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges