隐藏ListBox控件垂直滚动条 [英] Hide vertical scroll bar in ListBox control
问题描述
我正在开发,需要一个的ListBox
控件的应用程序。不幸的是,当我在的ListBox
添加过多物品,则会显示一个垂直滚动条。有什么我可以做隐藏由的ListBox
显示垂直滚动条?我可以看到,有一个属性来隐藏水平滚动条但没有属性的垂直滚动条。
I'm developing an application that requires a ListBox
control. Unfortunately, when I add too many items in the ListBox
, a vertical scroll bar is shown. Is there something I can do to hide the vertical scroll bar shown by the ListBox
? I can see that there's a property to hide the horizontal scroll bar but there's no property for the vertical scroll bar.
推荐答案
问题解决了。我只是创建的模板的一个新项目,一个类库用下面的代码使用系统
The problem was solved. I've simply created a new project of template a class library with the following code
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
Then, I've built the project outputting a new class library ClassLibrary1.dll
在我的主要项目中,我已经用鼠标右键单击 工具箱
并选择 选择项目...
。点击浏览... 并选择了我最近创建的类库(ClassLibrary1.dll)并点击打开,然后在确定 。因此,我可以有我的自定义的ListBox
它没有垂直滚动条了。
On my main project, I've right-clicked the ToolBox
and selected Choose Items...
. Clicked on Browse... and selected the class library that I've recently created (ClassLibrary1.dll) and clicked on Open then on OK. Thus, I was able to have my custom ListBox
which has no vertical scroll bars anymore.
这篇关于隐藏ListBox控件垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!