> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/controls/scrollviewer/verticalscrollbarvisibility.md).

# VerticalScrollBarVisibility

## Introduction

VerticalScrollBarVisibility controls the visibility of the vertical scroll bar, specifically in regards to the number of items in the ScrollViewer. The available values are:

* Auto - the ScrollBar displays only if needed based on the size of the inner panel
* Hidden - the ScrollBar remains invisible even if the contents of the inner panel exceed the size of its container
* Visible - the ScrollBar always displays

## Default Behavior

The default is Auto which means that the scroll bar only displays if necessary. This can be modified to change the ScrollBar behavior.

```csharp
// Initialize
var scrollViewer = new ScrollViewer();
scrollViewer.AddToRoot();
scrollViewer.X = 50;
scrollViewer.Y = 50;
scrollViewer.Width = 200;
scrollViewer.Height = 200;
scrollViewer.InnerPanel.StackSpacing = 2;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

var button = new Button();
button.AddToRoot();
button.Text = "Add Item";
button.X = 50;
button.Y = 10;
var random = new System.Random();
button.Click += (_, _) =>
{
    var innerRectangle = new ColoredRectangleRuntime();
    // no need to set innerRectangle.Y since each rectangle stacks
    innerRectangle.Width = 30;
    innerRectangle.Height = 30;
    innerRectangle.Color = new Color(random.Next(255), random.Next(255), random.Next(255));
    scrollViewer.InnerPanel.Children.Add(innerRectangle);
};
```

<figure><img src="/files/DyUSprl4cjCjOE1K1epf" alt=""><figcaption><p>VerticalScrollBarVisibility set to Auto only shows the ScrollBar if enough items are added to the ScrollView</p></figcaption></figure>

## Code Example: Setting a ScrollViewer's VerticalScrollBarVisibility

The following code sets the visibility to never show:

```csharp
// Initialize
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flatredball.com/gum/code/controls/scrollviewer/verticalscrollbarvisibility.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
