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.

- 5,475
- 3
- 23
- 37
-
If you remove the vertical scroll bar then how would users access the items past the edge of the scroll? – Lee Taylor Nov 01 '12 at 01:50
-
@LeeTaylor Thanks for replying. I've forgot to mention that I have a RichTextBox. I've managed to control the listbox within the RichTextBox. So, there's no need to show scroll bars in the listbox. Have a great day :) – Picrofo Software Nov 01 '12 at 01:52
-
OK, I'm not aware of any way to remove the scroll bars. The only way I know is to make sure the listbox is long enough to hold all your items. – Lee Taylor Nov 01 '12 at 01:54
2 Answers
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();
}
}
}
}
}
Then, I've built the project outputting a new class library ClassLibrary1.dll
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.

- 834
- 1
- 7
- 17

- 5,475
- 3
- 23
- 37
Except from the horizontal scroll-bar, there is no way with normal use you can turn off the vertical scroll-bar.
You can only set it always visible or auto using the property ScrollAlwaysVisible
(also in VB).
When you add item you can instead re-calculate ClientSize by calculating, something like this (untested, you might need to add Padding values to it as well):
Size sz = new Size(ListBox1.ClientSize.Width, _
ListBox1.Items.Count * ListBox1.Font.Height);
ListBox1.ClientSize = sz
Of course, you should add check to the value in case it is zero, and/or you want a minimum/maximum height.
-
Thank you, I've successfully hid the vertical scroll bar creating a class library. I'll post my solution in a moment :) – Picrofo Software Nov 01 '12 at 02:09
-
1Nice :-) As you asked if it could be done with the ListBox control I'll leave my answer as-is :-) – Nov 01 '12 at 02:29