Question

I've got this UserControl derived from ScrollableControl and I only wish to show a vertical scrollbar. As by no means I can configure to only show the vertical scrollbar, no matter what. It seems like a flaw of winforms. Another problem is that whenever the parent resizes, making the control less wide, the horizontal scrollbar is shown immediately until the OnResize event handler adjusts the width. As a result the horizontal scrollbar flickers, as its contents it temporary wider than the width of the scrollabe control. This makes the components inside the scrollable control redraw unnecessary times as they adjust to the available space. When the control is made wider, the horizontal scrollbar is never shown.

So I googled around and found this: Add vertical scroll bar to panel in .NET

Seems promosing, but now both scrollbars, and the contents of the panel are flickering whenever it is scrolled by this external scrollbar. The problem of resizing the panel to become less width, showing and hiding the horizontal scrollbar, and causing unnecessary redraws is no more though, so thats a win.

This is what the constructor of the control looks like:

        public BarGraphPanel()
        {
            this.HScroll = false;
            this.VScroll = false;
            this.AutoScroll = false;
            this.VerticalScroll.Visible = false;
            this.HorizontalScroll.Visible = false;
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.DoubleBuffered = true;
        }

What it should look like while scrolling:

enter image description here

What it looks like while scrolling:

enter image description here

That the textboxes aren't drawn so nicely while scrolling is something I can accept, but both scrollbars flickering (so temporary showing actually 3 scrollbars!) is madness.

Is there a way of only having one scrollbar on screen (always) without any of the other bars or its contents flickering?

Was it helpful?

Solution

The answer of MajinFro here actually helped me out: During FlowLayoutPanel scrolling, background distorts + flickers

When I do not override CreateParams as suggested, it doesn't work, so that does seem like a essential 'trick'.

OTHER TIPS

set on panel scrolling event this code:

private void panel1_Scroll(object sender, ScrollEventArgs e)
    {
        panel1.Invalidate();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top