【求助】Unity里面可以用System.Windows.Forms的DragDrop和DragEnter方法吗

qq_35525966 2017-12-28 02:25:03
我想打开U3D发布的PC窗口,实现桌面文件拖入窗口显示选择的文件路径,网上都是在winform里面的,我应用了dll,但是没有效果

using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour {

public Text txt;

private void Start()
{
Form1 form = new Form1(txt);
}
}

public class Form1 : Form
{
Text txt;
public Form1(Text txt)
{
this.txt = txt;
InitializeComponent();
}

private void InitializeComponent()
{
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new DragEventHandler(this.Form1_DragEnter);
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
txt.text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
}
...全文
217 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,526

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧