Click here to Skip to main content
15,845,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

On my form, I have a panel with a varying number of buttons. They are all placed in a row and are all set to dock top. Since I dislike the design of the included scrollbars and the lack of possibility to change the color, I created my own scrollbar, which works great. The problem is that in order for it to work, AutoScroll must be set to true. Now, when the summed height of the content exceeds the height of the panel, the standard scrollbar automatically appears and I can not get rid of it.

So here is my question. How can I make the scrollbar disappear?

What I have tried:

I tried every combination like for example

panel_Playlists.AutoScroll = false;
panel_Playlists.VerticalScroll.Enabled = false;
panel_Playlists.VerticalScroll.Visible = false;
panel_Playlists.AutoScroll = true;
Updated 6-May-18 12:31pm

One way is to call ShowScrollBar directly from user32.dll.

Have a look at Problem to hide vertical scrollbar in panel control.[^]
Share this answer
Member 13814072 6-May-18 14:08pm    
It only works to 50%. If I do not do anything, the ScrollBar will not be visible either. However, if I scroll and change panel.VerticalScroll.Value, the ScrollBar will be displayed again until I stop
Wendelius 6-May-18 14:16pm    
After setting the value, simply call the function again. The function call does not need to be in WndProc. Consider following example
      private void button1_Click(object sender, EventArgs e) {
         panel1.VerticalScroll.Value = panel1.VerticalScroll.Value + 1;
         ShowScrollBar(panel1.Handle, (int)ScrollBarDirection.SB_VERT, false);

      private void Form1_Activated(object sender, EventArgs e) {
         ShowScrollBar(panel1.Handle, (int)ScrollBarDirection.SB_VERT, false);
Member 13814072 6-May-18 14:28pm    
now it's appearing, disappearing, appearing... every time I move my mouse while dragging the scrollthump ;)
Wendelius 6-May-18 14:32pm    
That's quite odd. I did a small test with the code above and everything wotks just fine.

Ensure that you don't set the autoscroll anywhere and that there is no other code affecting this. For example have you wired the Scroll event...
Member 13814072 6-May-18 14:41pm    
I'm not using the scroll event. I'm using the OnValueChanged event which I created myself and which is called when the value of the scrollbar is changing/set. The only position where I'm setting autoscroll is in InitializeComponent()
The general solution to this problem requires nested panels. The inner panel is allowed to resize to fit it's contents and does not show scrollbars. The outer panel has AutoSize false and AutoScroll false. By changing the location of the inner panel it may be moved (scrolled) within the outer panel.

This is the idea
Panel outerPanel = new Panel();
outerPanel.AutoSize = false;
outerPanel.AutoScroll = false;
// For testing make the bounds very obvious
outerPanel.BackColor = Color.Red;
outerPanel.BorderStyle = BorderStyle.FixedSingle;

Panel innerPanel = new Panel();
innerPanel.Parent = outerPanel;
innerPanel.AutoSize = true;
innerPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
innerPanel.AutoScroll = false;
innerPanel.BorderStyle = BorderStyle.FixedSingle;
innerPanel.BackColor = Color.Blue;

// Scroll down a bit, right a bit
innerPanel.Location = new Point(-50, -30);

Share this answer
Member 13814072 6-May-18 18:21pm    
Okay, that works the way I want it, but somehow it's very from behind through the chest into the eye (awkward)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900