我正在尝试制作一个允许将文件拖放到ListView
. 我ListView.InsertionMark
用来确定在哪里插入文件。当我删除文件时,InsertionMark
它不会消失,因为DragLeave
事件没有被触发;如果我将拖放效果更改为DragDropEffects.None
,则DragLeave
释放鼠标时会触发该事件。为什么会这样?
此外,该文档说“如果键盘或鼠标按钮状态发生变化,QueryContinueDrag
则引发事件并Action
根据事件的QueryContinueDragEventArgs
。” 但是该QueryContinueDrag
事件也没有被触发。
public partial class MainForm : Form
{
private ListView listView1 = new ListView();
public MainForm()
{
InitializeComponent();
this.Controls.Add(listView1);
listView1.Dock = DockStyle.Fill;
listView1.View = View.Details;
listView1.Columns.Add("Test");
listView1.Items.Add("0");
listView1.AllowDrop = true;
listView1.DragEnter += listView1_DragEnter;
listView1.DragOver += listView1_DragOver;
listView1.DragLeave += listView1_DragLeave;
listView1.DragDrop += listView1_DragDrop;
listView1.GiveFeedback += listView1_GiveFeedback;
listView1.QueryContinueDrag += listView1_QueryContinueDrag;
}
private void listView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link | DragDropEffects.Scroll;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listView1_DragOver(object sender, DragEventArgs e)
{
// This is not done, only to show this problem.
listView1.InsertionMark.Index = 0;
listView1.InsertionMark.AppearsAfterItem = true;
}
private void listView1_DragLeave(object sender, EventArgs e)
{
listView1.InsertionMark.Index = -1;
}
private void listView1_DragDrop(object sender, DragEventArgs e)
{
// listView1.InsertionMark.Index = -1; // Is this really necessary?
}
private void listView1_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
this.Text = "listView1_QueryContinueDrag";
}
private void listView1_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
this.Text = "listView1_GiveFeedback";
}
}
我是否必须listView1.InsertionMark.Index = -1
手动设置才能隐藏InsertionMark
?DragLeave
当拖放效果为时,是否有触发事件DragDropEffects.Link
?