C# Winforms - 控件的滚动条何时初始化?
情况如下:
我试图从 devexpress 控件 VerticalScroll 控制 flowLayoutControl 的滚动条。
现在 - flowLayoutControl 与 autoscroll = true。我添加了一个新的垂直滚动控件并将其停靠在右侧。现在,Devexpress Vertical Scroll 控件位于 FlowLayout 滚动条的正上方。
另外,运行以下代码时,FlowLayoutPanel 垂直滚动不会隐藏:
spotWinFlowLayout1.VerticalScroll.Visible = false
我已经设置了以下事件处理程序:
private void spotWinFlowLayout1_Resize(object sender, EventArgs e)
{
SetupVerticalScrollBar();
}
private void SetupVerticalScrollBar()
{
vScrollBar1.Minimum = spotWinFlowLayout1.VerticalScroll.Minimum;
vScrollBar1.Maximum = spotWinFlowLayout1.VerticalScroll.Maximum;
vScrollBar1.LargeChange = spotWinFlowLayout1.VerticalScroll.LargeChange;
vScrollBar1.SmallChange = spotWinFlowLayout1.VerticalScroll.SmallChange;
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
spotWinFlowLayout1.VerticalScroll.Value = e.NewValue;
}
一切正常,除了在表单 Load 上时,flowLayoutControl 上已经有一个滚动条, spotWinFlowLayout1.VerticalScroll.XXX 属性尚未设置。所以两个滚动条都不同步。但一旦我调整表单大小,两者就会同步。
那么 FlowLayoutPanel 的滚动条何时初始化?
Here is the situation:
I am trying to control flowLayoutControl's scroll bar from devexpress controls VerticalScroll.
Now - flowLayoutControl with autoscroll = true. I added a new verticalscroll control and dock it to Right. So now the Devexpress Vertical Scroll control is right on top of FlowLayout scrollbar.
Also the FlowLayoutPanel vertical scroll does not hide when following code is run:
spotWinFlowLayout1.VerticalScroll.Visible = false
I have setup the following event handlers:
private void spotWinFlowLayout1_Resize(object sender, EventArgs e)
{
SetupVerticalScrollBar();
}
private void SetupVerticalScrollBar()
{
vScrollBar1.Minimum = spotWinFlowLayout1.VerticalScroll.Minimum;
vScrollBar1.Maximum = spotWinFlowLayout1.VerticalScroll.Maximum;
vScrollBar1.LargeChange = spotWinFlowLayout1.VerticalScroll.LargeChange;
vScrollBar1.SmallChange = spotWinFlowLayout1.VerticalScroll.SmallChange;
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
spotWinFlowLayout1.VerticalScroll.Value = e.NewValue;
}
Everything is working fine except when on form Load there is already a scrollbar on flowLayoutControl,
spotWinFlowLayout1.VerticalScroll.XXX properties not set yet. So both the scrollbars are out of Sync. But as soon as I resize the form both get Sync.
So when is scrollbar for the FlowLayoutPanel initialized?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能听起来像 smartalec 的答案:“当控件被绘制或放置在表单上时”,这就是当您调整表单大小时它们同步的原因。(它们再次被绘制)
解决办法是自己手动添加滚动条。
This might sound like a smartalec answer: "When the control is drawn or placed on the form" which is the reason when you adjust the size of the form they are in sync.( they are being drawn again )
The solution is to manually add the scrollbars yourself.