更新时间:2023-02-08 18:53:04
更新: @ taffer的回答解释了为什么你的$ C $Ç行为古怪。
Update: @taffer's answer explains why your code behaves odd.
您可以用code以下,我已经测试它;项目表现为你描述。
You can use the code below, I have tested it; Project behaves as you described.
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
{
if (Path.GetExtension(file[0]) == ".url")
{
//Do Stuff Here
//
}
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
if (Path.GetExtension(file[0]) == ".url")
{
e.Effect = DragDropEffects.Link;
//Do Stuff Here
}
}
在一个侧面说明了第二个问题:可能引发异常,使用尝试捕捉验证
On a side note for second question: Probably an exception being thrown, use try catch to verify.