我正在 visual studio 2017 中创建一个 winforms 应用程序,我正在使用 List 填充列表框。
我将多列属性设置为 true。由于我的列表中有很多字符串,因此框底部出现了一个水平滚动条。
我正在创建的应用程序应该在平板电脑上运行,因此滚动条不容易用手指导航。
我的问题是,有没有一种方法可以使用按钮来控制这个滚动条?
最佳答案
是的,可以在 Buttons
的帮助下控制您期望的行为。
从右向左移动-
private void btnLeft_Click(object sender, EventArgs e)
{
int visibleItemsInColumn = listBox1.ClientSize.Height / listBox1.ItemHeight; //No of items in each column. In this case - 5
listBox1.TopIndex = listBox1.TopIndex - visibleItemsInColumn;
}
从左到右移动-
private void btnRight_Click(object sender, EventArgs e)
{
int visibleItemsInColumn = listBox1.ClientSize.Height / listBox1.ItemHeight;
listBox1.TopIndex = listBox1.TopIndex + visibleItemsInColumn;
}
What it actually does is every time you click on button, It increases/decreases the TopIndex by the total elements per columns. So on each clicks, you move one column either left or right.
关于c# - 在 winforms 中使用按钮移动水平滚动条或列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50722564/