[英]How to hide the vertical scroll bar in a .NET ListView Control in Details mode
[英]Hide vertical scroll bar in ListBox control
我正在开发一个需要ListBox
控件的应用程序。 不幸的是,当我在ListBox
添加太多项时,会显示一个垂直滚动条。 我可以做些什么来隐藏ListBox
显示的垂直滚动条? 我可以看到有一个属性可以隐藏水平滚动条,但是垂直滚动条没有属性。
问题解决了。 我只是使用以下代码创建了一个模板类库的新项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class MyListBox : System.Windows.Forms.ListBox
{
private bool mShowScroll;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
if (!mShowScroll)
cp.Style = cp.Style & ~0x200000;
return cp;
}
}
public bool ShowScrollbar
{
get { return mShowScroll; }
set
{
if (value != mShowScroll)
{
mShowScroll = value;
if (IsHandleCreated)
RecreateHandle();
}
}
}
}
}
然后,我构建了输出新类库ClassLibrary1.dll
的项目
在我的主项目中,我右键单击了ToolBox
并选择了Choose Items...
单击Browse ...并选择我最近创建的类库(ClassLibrary1.dll)并单击Open然后单击OK 。 因此,我能够拥有自定义ListBox
,它不再有垂直滚动条。
除了水平滚动条,正常使用无法关闭垂直滚动条。
您只能使用属性ScrollAlwaysVisible
(也在VB中)将其设置为始终可见或自动。
当您添加项目时,您可以通过计算来重新计算ClientSize,类似这样(未经测试,您可能还需要向其添加填充值):
Size sz = new Size(ListBox1.ClientSize.Width, _
ListBox1.Items.Count * ListBox1.Font.Height);
ListBox1.ClientSize = sz
当然,您应该在值为零时添加检查值,和/或您想要最小/最大高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.