简体   繁体   English

AutoScrollMinSize在窗体Minimize / Maximize上出现故障

[英]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.

相关问题 c#最大化,最小化和关闭表单上的按钮 - c# Maximize, Minimize and Close buttons on form c# 表单最小化/最大化按钮不见了? - c# Form Minimize/Maximize Buttons gone? 使用两种KeyDown方法不起作用来最大化/最小化表单 - Maximize/Minimize Form With Two KeyDown Methods Not Working 绘制或隐藏控制框以实现无边界形式,同时最大化和最小化 - Paint or Hide Control Box for Borderless Form while maximize and minimize 如何在 Windows 窗体应用程序中设计自定义关闭、最小化和最大化按钮? - how to design a custom close, minimize and maximize button in windows form application? 如何从窗体中删除最大化图标并保留最小化 - how to remove the Maximize icon from form and leave the minimize SetWindowsHookEx,然后单击冻结表单上的最小化/最大化/关闭按钮 - SetWindowsHookEx and clicking minimize/maximize/close buttons on form freezing 隐藏表单上的最小化和最大化按钮,不隐藏标题 - Hide minimize and maximize buttons on form without hide title 关闭、最小化和最大化事件在自定义 WPF 表单模板中不起作用 - Close, minimize and maximize events do not work in a custom WPF form template 在 WinForm 上禁用最小化和最大化? - Disabling Minimize & Maximize On WinForm?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM