本文介绍了如何在下拉列表中设置水平滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个显示最多10个没有的下拉列表。项目和超过10,它应该使用水平滚动来上下移动。
我在vs2005用c#工作。
请告诉我是否可以通过任何财产,CSS和任何其他方式。
谢谢
I want to create a drop down list that shows max 10 no. of item and more than 10, it should use horizontal scroll to move up and down.
I am working in vs2005 with c#.
Please tell me if it is possible by any property, css and any other way.
thanks
推荐答案
private void DisplayHScroll()
{
// Make no partial items are displayed vertically.
listBox1.IntegralHeight = true;
// Add items that are wide to the ListBox.
for (int x = 0; x < 10; x++)
{
listBox1.Items.Add("Item " + x.ToString() + " is a very large value that requires scroll bars");
}
// Display a horizontal scroll bar.
listBox1.HorizontalScrollbar = true;
// Create a Graphics object to use when determining the size of the largest item in the ListBox.
Graphics g = listBox1.CreateGraphics();
// Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
int hzSize = (int) g.MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),listBox1.Font).Width;
// Set the HorizontalExtent property.
listBox1.HorizontalExtent = hzSize;
}
这篇关于如何在下拉列表中设置水平滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!