SamAyoub95
SamAyoub95

Reputation: 27

C# Hide Panel Scroll Bar

i'm Trying To Creating a Two Button To Scroll My Panel (Up And Down)

Picture Of My Form

My Scroll DownButton

  private void button_Category_Down_Click(object sender, EventArgs e)
    {

            int CurrentVal = flowLayoutPanel_Categories.VerticalScroll.Value;


            if (value > CurrentVal)
            {
                value = CurrentVal - 75;
              return;
            }

            value += 70;

            flowLayoutPanel_Categories.AutoScrollPosition = new Point(0, value);


    }

And The Scroll Up Button

  private void button_Category_Up_Click(object sender, EventArgs e)
    {


            if (value <= 0)
            {
                value = 0;
                return;
            }

            value -= 75;

            flowLayoutPanel_Categories.AutoScrollPosition = new Point(0, value);

    }

My Codes Are working Fine BUT ONlY If Panel Properties [AutoScroll] is set to true

And when autoscroll is true , the ScrollBar will be Visible

how Can i Have The Scroll Bars

i tried

      private const int SB_BOTH = 3;
    private const int WM_NCCALCSIZE = 0x83;

    [DllImport("user32.dll")]
    private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);

    protected override void WndProc(ref Message m)
    {

        ShowScrollBar(flowLayoutPanel_Categories.Handle, SB_BOTH, 0 /*Hide the ScrollBars*/);


        base.WndProc(ref m);
    }

but its not working probably

and if i set the autoscroll to false, the buttons will not work

sorry for my bad english, and thanks

Upvotes: 0

Views: 2328

Answers (1)

brett
brett

Reputation: 791

Updated answer for windows Forms:

Right, so I updated my anser to address your comment, where you state this is a Windows Forms project, not an UWP Project like I had assumed based on your mock-up image.

The only fast way (more like a workaround, actually) I can think of right now is to embed your panel inside a container that is smaller than your content panel in such a way that the scrollbar region falls outside of the displayed area (see image below), or simply place another object over the panel so that it covers the scrollbar region.

enter image description here

Keep in mind to check your design in all Windows versions that your program supports. Certain Windows themes (i.e. Windows 10) could reserve less or more space for the scrollbar, resulting in either partly visible scrollbar, or clipped container content. Also check out what happens when the content does not require scroll. Setting scroll to auto would probably hide the scrollbar completely in such a scenario on certain Windows versions, so that content might get clipped if it fills the panel.

UWP solution:

In UWP windows 10 apps, you can right click an object in the designer windows > Edit Template > Edit a Copy and edit appearance on sub-components of the selected component Edit appearance of an element by performing changes to its template

Then you just edit the scroll viewer component hat should be part of your panel and set Vetical scrollbar to false .

Change properties of sub-objects, in this case Scrollviewer

Upvotes: 0

Related Questions