【发布时间】:2017-07-26 23:21:01
【问题描述】:
在 Form1 和 textBox1 上都启用了 AllowDrop。这些事件在执行 DragDrop 和 DragEnter 时启用并启动。我已经尝试重新排列代码,以便 textBox1_DragEnter 位于 textBox1_DragDrop 之前,但这不起作用。这段代码有什么问题?
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
FileInfo fi = new FileInfo((string)e.Data.GetData(DataFormats.FileDrop));
byte[] ba = Encoding.Default.GetBytes(fi.OpenText().ToString().ToCharArray());
textBox1.Text = ba.ToString();
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string file = (string)e.Data.GetData(DataFormats.FileDrop);
if (Path.GetExtension(file) != "dat")
{
s = "broken file";
}
}
}
【问题讨论】:
-
您必须向我们展示您的“未显示”代码。
-
我添加了它。对不起。
-
如果您打开了 UAC 并且您以管理员身份运行该程序,您将无法从 Windows 资源管理器中将某些内容拖放到您的表单中。