在ListBox控件中隐藏垂直滚动条

Pic*_*are 7 c# listbox winforms

我正在开发一个需要ListBox控件的应用程序.不幸的是,当我在其中添加太多项目时ListBox,会显示一个垂直滚动条.我可以做些什么来隐藏显示的垂直滚动条ListBox?我可以看到有一个属性可以隐藏水平滚动条,但是垂直滚动条没有属性.

Pic*_*are 8

问题解决了.我只是使用以下代码创建了一个模板类库的新项目

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();
                }
            }
        }
    }    
}
Run Code Online (Sandbox Code Playgroud)

然后,我构建了输出新类库的项目 ClassLibrary1.dll

在我的主项目中,我右键单击ToolBox并选中Choose Items....单击Browse ...并选择我最近创建的类库(ClassLibrary1.dll)并单击Open然后单击OK.因此,我能够ListBox拥有没有垂直滚动条的自定义.