Monday, August 29, 2011

Hiding the scroll bar in Checklistbox

Recently I was working on a checklist box control, which was disabled  but did not prevent the vertical scroll bar from appearing. As I had to to keep the checklist box disabled,  I added a panel  on to the checklist box, but still the horizontal scroll bar was visible. Please see the comparison in the picture.



The only resolution I could come was to hide the scroll bar of the checklist box from appearing. I wrote the following code and instantiated an object of it, and it did the trick.



class CustomCheckListBox : System.Windows.Forms.CheckedListBox
{
        private const int WS_VSCROLL = 0x00200000;
        protected override System.Windows.Forms.CreateParams CreateParams
        {
            get
            {
                System.Windows.Forms.CreateParams parms = base.CreateParams;
                parms.Style &= ~WS_VSCROLL;
                return parms;
            }
        }
}

No comments: