我正在开发一个需要 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...
。单击浏览... 并选择我最近创建的类库 (ClassLibrary1.dll),然后单击打开,然后单击确定 .因此,我能够拥有不再有垂直滚动条的自定义 ListBox
。
关于c# - 隐藏ListBox控件中的垂直滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13169900/