先建立好ListView,ImageList,
然后编写一个比较类
在就是添加DragDrop事件了
具体实现看代码吧
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeListView();
}
// 初始化listView1.
private void InitializeListView()
{
listView1.ListViewItemSorter = new ListViewIndexComparer();
//初始化插入标记
listView1.InsertionMark.Color = Color.Red;
//
listView1.AllowDrop = true;
}
// 当一个项目拖拽是启动拖拽操作
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
listView1.DoDragDrop(e.Item, DragDropEffects.Move);
}
private void listView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.AllowedEffect;
}
//像拖拽项目一样移动插入标记
private void listView1_DragOver(object sender, DragEventArgs e)
{
// 获得鼠标坐标
Point point = listView1.PointToClient(new Point(e