题
我正在写一个应用程序。净使用的自动滚动为布置小组中的对话。看来,只要我调整的窗口,以便垂直滚动应该出现的滚动水平会自动出现。密切关注它,第二滚动现在允许我滚动的窗口由16素(宽度的其他滚动).所以,窗户似乎认为我需要一个客户区,至少是尽可能广泛,因为它是以前的垂直滚动出现。
如果我现在调整窗口的16个象素更广泛的(因此,我的窗口领域是广泛的,因为它是以前的滚动条中出现),滚动消失。现在,如果我调整它回到它是什么,它保持距离。
因此它似乎我有一个错误,在该系统里最低的宽度是某种粘稠,但是扩大和downsizging窗口(用鼠标,以及没有tuching的滚动相关的Api)清除状况
有没有人知道的一个解决方法,或者我在做的东西行了窗户?
没有正确的解决方案
其他提示
是的,我想你已经正确地诊断问题。这是,说,垂直滚动条出现并需要空间,使得客户可用面积小讨厌的副作用。太小,放不下的控制,现在也使水平滚动条出现。它实际上是双稳态的,水平杆可在某些情况下的闪烁开启和关闭。
要避免这种影响,布局引擎将具有通过所述布局进行多次传递,处理不断变化的工作区。但是,由于它只会让一个人通过。这听起来很明智的,这可能是一个潜在的永无止境的循环。我不知道这个体面的修复。您的用户将很可能只是调整窗口的大小足够大,以摆脱滚动条的至少一个。
这是一个已知的错误,在windows 在这里,
最好的办法来解决这个问题是把桌布局面autosized内的另一个小组,对接到的主要形式,并设置与自动滚动=true
所以你不再使用的tablelayoutpanel滚动这是越野车,你使用专家组的滚动和tablelayoutpanel是内部小组
我不完全注意到您所描述的行为,但已运行到其中垂直滚动条的外观进行必要的水平滚动条的情况。
您可以设置面板的内容,以允许滚动条的宽度,例如,如果我在一个ListBox
一个Panel
:
listBox1.Width = panel2.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
HTH
我只遇到过这个问题。我用此修复程序是一套Scrollable
到false
再到true
。这是一个带ListView
Resize
事件的示例:
private void myListView_Resize(object sender, EventArgs e)
{
this.SuspendLayout();
//Code to do various resizing stuff
//Force Scrollbar Recalculation
myListView.Scrollable = false;
myListView.Scrollable = true;
this.ResumeLayout(false);
this.PerformLayout();
}
如果Scrollable
并非总是如此,你可以重新计算条件。
尽管这是一个老问题,它仍然是一个问题。净4.具有读尽我所能找到的关于这个问题,我已经卷组合的解决方案的一个辅助课。
第一,这里是结果,我拍摄...我有一个小组,其中包含各种各样的控制。孩子的控制,以及它们的大小,可以改变基于用户活动。我希望小组要调整水平,以便没有水平滚吧,但如果没有足够的空间垂直方向,我想垂直滚动条出现。另外,垂直滚吧不能涵盖任何我的孩子控制时,它的出现,而我不想离开一个缺口,它时,它不是必要的。
两个'错误的,我的助手类尝试修复是首先,从来没有显示水平的滚动条,和第二,在垂直滚动栏显示,该小组的宽度自动增加,以容纳。
我的假设是,该小组被设定为自动调整大小和自动滚动以及儿童的控制是设置自动调整大小。
该解决方案
Helper类本身重视小组(通过处理的油漆和SizeChanged事件),并做两件事。第一,它禁用水平滚动吧。这是不容易的,因为它的声音,和我找到了这个问题的解决办法在这里 水平滚动条的答案通过Μ Subrahmanyam.第二,在回应的油漆和SizeChanged事件,以及一个背景定时,检查,看见酒店的垂直滚动条已经改变。如果是这样,在帮助类改变了正确的填充的财产的小组中添加或删除的额外空间的滚动条的要求。使用各种小组的活动和计时器是必需的,因为。净暴露了 没有 事件在所有的滚动条(一个大的设计缺陷恕我直言).
一旦最后一点是,你不能做任何的变化大小的小组,同时处理的SizeChanged事件。不好的东西(tm)发生,如果你这样做。所以,如果我需要改变填补由于SizeChanged事件,我计划改变对于后。
无论如何,这里的代码助手类。它假定你有所有的适当使用发言,包括一个系统。穿...
/// <summary>
/// This class is intended to beat the AutoSize and AutoScroll features into submission!
///
/// Or, at least getting them to work the way I want them to (which may not be the way
/// others think they should work).
///
/// This class will force a panel that has AutoSize enabled to actually increase its
/// width as appropriate when the AutoScroll Vertical scroll bar becomes visible.
/// I like this better than attempting to 'reserve' space for the Vertical scroll bar,
/// which wastes space when the scroll bar is not needed, and leaves ugly gaps in
/// your user interface.
/// </summary>
public class AutoScrollFixer
{
/// <summary>
/// This is the panel we are 'fixing'
/// </summary>
private Panel _panel;
/// <summary>
/// This field keeps track of the original value for
/// the right padding property of the panel.
/// </summary>
private int _originalRightPadding = 0;
/// <summary>
/// We use this flag to prevent recursion problems.
/// </summary>
private bool _adjusting = false;
/// <summary>
/// This flag keeps track of the last known state of the scroll bar.
/// </summary>
private bool _lastScrollBarVisible = false;
/// <summary>
/// We use a timer to check the scroll bar state every so often.
/// This is necessary since .NET (in another stunning piece of
/// architecture from Microsoft) provides absolutely no events
/// attached to the scroll bars of a panel.
/// </summary>
private System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer();
/// <summary>
/// Construct an AutoScrollFixer and attach it to the provided panel.
/// Once created, there is no particular reason to keep a reference
/// to the AutoScrollFixer in your code. It will silently do its thing
/// in the background.
/// </summary>
/// <param name="panel"></param>
public AutoScrollFixer(Panel panel)
{
_panel = panel;
_originalRightPadding = panel.Padding.Right;
EnableVerticalAutoscroll(_panel);
_lastScrollBarVisible = _panel.VerticalScroll.Visible;
_panel.Paint += (s, a) =>
{
AdjustForVerticalScrollbar();
};
_panel.SizeChanged += (s, a) =>
{
//
// We can't do something that changes the size while handling
// a size change. So, if an adjustment is needed, we will
// schedule it for later.
//
if (_lastScrollBarVisible != _panel.VerticalScroll.Visible)
{
AdjustLater();
}
};
_timer.Tick += (s, a) =>
{
//
// Sadly, the combination of the Paint event and the SizeChanged event
// is NOT enough to guarantee that we will catch a change in the
// scroll bar status. So, as a last ditch effort, we will check
// for a status change every 500 mSecs. Yup, this is a hack!
//
AdjustForVerticalScrollbar();
};
_timer.Interval = 500;
_timer.Start();
}
/// <summary>
/// Enables AutoScroll, but without the Horizontal Scroll bar.
/// Only the Vertical Scroll bar will become visible when necessary
///
/// This method is based on this StackOverflow answer ...
/// https://stackoverflow.com/a/28583501/2175233
/// </summary>
/// <param name="panel"></param>
public static void EnableVerticalAutoscroll( Panel panel )
{
panel.AutoScroll = false;
panel.HorizontalScroll.Enabled = false;
panel.HorizontalScroll.Visible = false;
panel.HorizontalScroll.Maximum = 0;
panel.AutoScroll = true;
}
/// <summary>
/// Queue AdjustForVerticalScrollbar to run on the GUI thread after the current
/// event has been handled.
/// </summary>
private void AdjustLater()
{
ThreadPool.QueueUserWorkItem((t) =>
{
Thread.Sleep(200);
_panel.BeginInvoke((Action)(() =>
{
AdjustForVerticalScrollbar();
}));
});
}
/// <summary>
/// This is where the real work gets done. When this method is called, we will
/// simply set the right side padding on the panel to make room for the
/// scroll bar if it is being displayed, or reset the padding value to
/// its original value if not.
/// </summary>
private void AdjustForVerticalScrollbar()
{
if (!_adjusting)
{
try
{
_adjusting = true;
if (_lastScrollBarVisible != _panel.VerticalScroll.Visible)
{
_lastScrollBarVisible = _panel.VerticalScroll.Visible;
Padding p = _panel.Padding;
p.Right = _lastScrollBarVisible ? _originalRightPadding + System.Windows.Forms.SystemInformation.VerticalScrollBarWidth + 2 : _originalRightPadding;
_panel.Padding = p;
_panel.PerformLayout();
}
}
finally
{
_adjusting = false;
}
}
}
}