[英]AutoScrollMinSize glitches on form Minimize/Maximize
I have a custom UserControl with a function that updates the AutoScrollMinSize each time the control is resized. 我有一个自定义UserControl,其功能是每次调整控件大小时都会更新AutoScrollMinSize。 This control is set to DockStyle.Fill inside a parent form with some other controls. 将此控件设置为DockStyle.Fill,并将其与其他控件一起放在父窗体中。
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. 我尝试过分别或一起订阅OnResize和OnSizeChanged,并且遇到相同的问题。 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. 我尝试过仅在新值不等于当前值的情况下设置AutoScrollMinSize(以防在将其两次设置为相同值时出现小故障),但是我仍然遇到这个问题。
My control styles are as follows: 我的控件样式如下:
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.ResizeRedraw, true);
this.DoubleBuffered = true;
this.AutoScroll = true;
Not a perfect solution, but I found that calling PerformLayout() after I set AutoScrollMinSize forces the scroll bars to show. 这不是一个完美的解决方案,但是我发现在设置AutoScrollMinSize之后调用PerformLayout()会强制滚动条显示。
AutoScrollMinSize = newSize;
PerformLayout();
Invalidate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.