C#列表拖放

一 列表显示

ListBox列表项的自定义显示:
ListDrawSupport.cs
DrawMode:OwnerDrawVariable;
MeasureItem:设定行高;
DrawItem:绘制列表项;

MouseDown:鼠标按下时,记住起始数据;
MouseMove:启动拖放操作;
MouseUp:结束;

拖放开始时,应根据鼠标点击的位置确定被拖拽的项。

dragStartIndex=list.IndexFromPoint(e.Location);

t拖拽的数据可以完全自己定义,类型Text值,列表项的索引。

transfer.Setdata("Text",this.dragStartIndex+")

二 接受拖放

接受拖放:从外部拖有一个文本到列表框。
修改DragList.cs
① AllowDrop:True;
② DragEnter:允许;
③ DragDrop:取出数据,插入列表项;
④ DragLeave:无操作;

你可能感兴趣的:(C#,c#,ui)