Question

I have a custom UserControl with a function that updates the AutoScrollMinSize each time the control is resized. This control is set to DockStyle.Fill inside a parent form with some other controls.

My problem is that when I minimize or maximize the container form, it sends two consecutive resize events and for some reason my scroll bars disappear.

When I resize the form by resizing the form border, the scroll bars update perfectly every time. It's only when I minimize or maximize that the scroll bars disappear.

I've tried subscribing to both OnResize and OnSizeChanged separately or together and have the same problem. I've tried only setting AutoScrollMinSize if the new value is not equal to the current value (in case there was some glitch in setting it twice to the same value) but I still have this problem.

My control styles are as follows:

this.SetStyle(ControlStyles.DoubleBuffer |
              ControlStyles.AllPaintingInWmPaint |
              ControlStyles.UserPaint |
              ControlStyles.ResizeRedraw, true);

this.DoubleBuffered = true;
this.AutoScroll = true;
Était-ce utile?

La solution

Not a perfect solution, but I found that calling PerformLayout() after I set AutoScrollMinSize forces the scroll bars to show.

AutoScrollMinSize = newSize;
PerformLayout();
Invalidate();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top