你们知道.net ListView-Replacement可以高度定制吗? 我正在开发一个类似于“待办事项”列表的应用程序。 我希望能够自定义列表的几乎所有视觉细节,所以我得到这样的东西:
我也希望能够通过鼠标重新排序项目+我需要拖放。 如果您不知道任何ListView,也许您知道如何从头开始制作我自己的列表视图?
感谢您的想法!
答案 0 :(得分:3)
使用WPF ListBox和ItemsTemplate :)查看http://msdn.microsoft.com/en-us/library/ms752347.aspx
答案 1 :(得分:3)
使用flowlayoutpanel控件作为容器,然后创建一个listitem的usercontrol,就在那里。 usercontrol可以具有您想要的任何外观,并将充当flowlayoutpanel中的listitem。然后我们有拖累和下降。遵循此代码(在此示例中为http://www.codeproject.com/KB/static/DragDropFlowLayoutPanel.aspx),您将在flowlayoutpanel中添加拖放项目:
首先创建一个新的windform-solution,然后创建一个只带有标签的usercontrol,我们将它作为你的特殊listitem-control的一个例子。将控件命名为MyListItem。将此代码粘贴到usercontrol中以使其可拖放:
Public Class MyListItem
Public Property AllowDrag() As Boolean
Get
Return m_AllowDrag
End Get
Set(ByVal value As Boolean)
m_AllowDrag = value
End Set
End Property
Private m_AllowDrag As Boolean
Private _isDragging As Boolean = False
Private _DDradius As Integer = 40
Private _mX As Integer = 0
Private _mY As Integer = 0
Public Sub New()
InitializeComponent()
Margin = New Padding(0)
AllowDrag = True
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
Me.BackColor = Color.Navy
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As EventArgs)
Me.BackColor = Color.Transparent
End Sub
Protected Overrides Sub OnClick(ByVal e As EventArgs)
Me.Focus()
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
Me.Focus()
_mX = e.X
_mY = e.Y
Me._isDragging = False
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
If Not _isDragging Then
If e.Button = MouseButtons.Left AndAlso _DDradius > 0 AndAlso Me.AllowDrag Then
Dim num1 As Integer = _mX - e.X
Dim num2 As Integer = _mY - e.Y
If ((num1 * num1) + (num2 * num2)) > _DDradius Then
DoDragDrop(Me, DragDropEffects.All)
_isDragging = True
Return
End If
End If
End If
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
_isDragging = False
End Sub
End Class
然后将flowlayoutpanel(flowlayoutpanel1)放到应用程序的主窗体上。
将此代码添加到表单中,它将使用可拖放的列表项填充flowlayoutpanel:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FlowLayoutPanel1.AllowDrop = True
For p As Integer = 0 To 50
Dim listitem As New MyListItem With {.Height = 50, .BorderStyle = BorderStyle.FixedSingle}
listitem.Label1.Text = "Item:" & p.ToString
FlowLayoutPanel1.Controls.Add(listitem)
Next
AddHandler FlowLayoutPanel1.DragEnter, AddressOf flowLayoutPanel_DragEnter
AddHandler FlowLayoutPanel1.DragDrop, AddressOf flowLayoutPanel1_DragDrop
End Sub
Sub flowLayoutPanel_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
e.Effect = DragDropEffects.All
End Sub
Private Sub flowLayoutPanel1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim data As MyListItem = CType(e.Data.GetData(GetType(MyListItem)), MyListItem)
Dim _destination As FlowLayoutPanel = CType(sender, FlowLayoutPanel)
Dim _source As FlowLayoutPanel = CType(data.Parent, FlowLayoutPanel)
If sender.Equals(data.Parent) Then
Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
Dim item = _destination.GetChildAtPoint(p)
Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
_destination.Controls.SetChildIndex(data, index)
_destination.Invalidate()
End If
End Sub
现在您可以启动程序并进行测试。您现在拥有一个“listview”,可以在其中包含自定义控件,并允许您拖放项目以更改项目顺序。
来自P.Sandgren的信用,用于拖放流程图面板中的项目:
http://www.codeproject.com/KB/static/DragDropFlowLayoutPanel.aspx
答案 2 :(得分:3)
您可以尝试ObjectListView(http://objectlistview.sourceforge.net)。
您可以获得以下丰富的功能:
Sample1 http://objectlistview.sourceforge.net/cs/_images/fancy-screenshot3.png
Sample2 http://objectlistview.sourceforge.net/cs/_images/foobar-lookalike.png
Sample3 http://objectlistview.sourceforge.net/cs/_images/task-list.png
要知道的一点是,您必须准备好在代码方面做很多事情,而不是通常的设计师视图,以便获得所需的功能级别。