C# 水平滚动winforms列表视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1044599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:52:54  来源:igfitidea点击:

Horizontal scroll winforms listview

c#winformslistviewscroll

提问by tempy

Anyone know if its possible to enable horizontal scrolling ONLY in a windows forms listview (viewmode set to large icons). What I want to do is make a listview whose height is sufficient to only show one row of icons, and I don't want to have multiple rows. Just one very long row that a user would have to scroll horizontally to get to out-of-range icons. If I make the listview scrollable then it automatically makes multiple rows and puts in a vertical scrollbar, which I don't want.

任何人都知道是否可以仅在 Windows 窗体列表视图中启用水平滚动(视图模式设置为大图标)。我想要做的是制作一个高度足以只显示一行图标的列表视图,我不想有多行。只有一个很长的行,用户必须水平滚动才能找到超出范围的图标。如果我使列表视图可滚动,那么它会自动生成多行并放入我不想要的垂直滚动条。

Thanks in advance!

提前致谢!

采纳答案by Fredrik M?rk

Set the Alignmentproperty to Left(or ListViewAlignment.Leftif you do it in code).

Alignment属性设置为Left(或者ListViewAlignment.Left如果您在代码中进行设置)。

回答by Tarek HAMZA

Just set one of the columns widths to: -2. the scroll bar will appear:

只需将列宽之一设置为:-2。滚动条会出现:

public Form1()
    {Listview1.Columns.Add("Name", 100, HorizontalAlignment.Center);
     Listview1.Columns.Add("Item Name", -2, HorizontalAlignment.Center);
     Listview1.Columns.Add("Item Link", 300, HorizontalAlignment.Center);
     }

When setting one or more of the columns width to -2, the scroll bar appears, I don't know why actually, but I had this problem because I fixed the width by creating an event that disables width change.

将一个或多个列宽设置为 -2 时,会出现滚动条,实际上我不知道为什么,但是我遇到了这个问题,因为我通过创建一个禁用宽度更改的事件来固定宽度。