在 vb/c#.net 中创建一个连续的列表(像一个轮子)
Create a continuous list (like a wheel) in vb/c#.net
在 windows 表单应用程序中,我需要一个一次只显示一个列表项但可以连续滚动的列表。例如,如果我的列表项是:
一个
乙
C
D
如果 D 是显示的项目,我向下滚动,它会返回到 A。这类似于命运之轮(虽然这不是我使用它的目的)。我认为列表控件会有一个连续滚动选项,但我没有找到这样的选项。
我想模仿这个(只是数字,不是实际的锁):
您可以使用 LinkList<T>
来模拟这个。我相信您可以在 winforms 中使用相同的逻辑,这样 ScrollSown
的每个事件都可以显示下一个项目
控制台
var linkList = new LinkedList<int>(new int[] { 1, 2, 3, 4 }.AsEnumerable());
var first = linkList.First;
LinkedListNode<int> current = first;
while (true)
{
Console.WriteLine($"Current value {current.Value}, press enter to Go Gext");
Console.ReadLine();
current = current.Next ?? first;
}
Console Output
WinForms
public LinkedList<object> linkList;
public LinkedListNode<object> current;
public LinkedListNode<object> first;
public Form1()
{
InitializeComponent();
linkList = new LinkedList<object>(new object[] { "A", "B", "C", "D" }.AsEnumerable());
first = linkList.First;
current = first;
listBox1.Items.Add(current.Value);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
current = current.Next ?? first;
listBox1.Items.Add(current.Value);
}
WinForm Output
在 windows 表单应用程序中,我需要一个一次只显示一个列表项但可以连续滚动的列表。例如,如果我的列表项是:
一个 乙 C D
如果 D 是显示的项目,我向下滚动,它会返回到 A。这类似于命运之轮(虽然这不是我使用它的目的)。我认为列表控件会有一个连续滚动选项,但我没有找到这样的选项。
我想模仿这个(只是数字,不是实际的锁):
您可以使用 LinkList<T>
来模拟这个。我相信您可以在 winforms 中使用相同的逻辑,这样 ScrollSown
的每个事件都可以显示下一个项目
控制台
var linkList = new LinkedList<int>(new int[] { 1, 2, 3, 4 }.AsEnumerable());
var first = linkList.First;
LinkedListNode<int> current = first;
while (true)
{
Console.WriteLine($"Current value {current.Value}, press enter to Go Gext");
Console.ReadLine();
current = current.Next ?? first;
}
Console Output
WinForms
public LinkedList<object> linkList;
public LinkedListNode<object> current;
public LinkedListNode<object> first;
public Form1()
{
InitializeComponent();
linkList = new LinkedList<object>(new object[] { "A", "B", "C", "D" }.AsEnumerable());
first = linkList.First;
current = first;
listBox1.Items.Add(current.Value);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
current = current.Next ?? first;
listBox1.Items.Add(current.Value);
}
WinForm Output