我的winform中有一个flowlayoutpanel
,动态添加图像。我希望vertical scroll bar
始终位于底部,显示最后添加的图像。我怎样才能做到这一点?
我有
AutoScroll = true
FLow Direction = Top Down
Wrap Content = False
答案 0 :(得分:7)
可滚动容器控件(如FlowLayoutPanel)会自动保持控件的焦点在视图中。但PictureBox很特别,它无法获得焦点。因此,您必须通过明确要求FLP使添加的控件可见来提供帮助,使用其ScrollControlIntoView()方法。像这样:
var pic = new PictureBox();
//...
flowLayoutPanel1.Controls.Add(pic);
flowLayoutPanel1.ScrollControlIntoView(pic);
具有强大的优势,这适用于您应用于FLP的任何布局设置。您还可以修改AutoScrollPosition属性,但更难做到这一点:
flowLayoutPanel1.AutoScrollPosition = new Point(
pic.Right - flowLayoutPanel1.AutoScrollPosition.X,
pic.Bottom - flowLayoutPanel1.AutoScrollPosition.Y);
答案 1 :(得分:1)
答案 2 :(得分:0)
这是一种强制最后一个控件进入视图的方法。
flowLayoutPanel.ScrollControlIntoView(Control_To_Add); // Control_To_Add is the control we want to scroll to
Button TempButton = new Button();
TempButton.Width = _Panel.ClientRectangle.Width - 6; // Make the last control in the _Panel
flowLayoutPanel.Controls.Add(TempButton); // We add this TempButton so we can scroll to the bottom of the _Panel.Controls
flowLayoutPanel.ScrollControlIntoView(b); // We scroll to TempButton at the bottom of the _Panel.Controls
flowLayoutPanel.Controls.Remove(b); // We remove TempButton
b.Dispose(); // clean up
答案 3 :(得分:0)
强制FlowLayoutPanel滚动并显示所有控件。 代码更正:
flowLayoutPanel.ScrollControlIntoView(Control_To_Add); // Control_To_Add is the control we want to scroll to
Button TempButton = new Button();
TempButton.Width = _Panel.ClientRectangle.Width - 6; // Make the last control in the _Panel
flowLayoutPanel.Controls.Add(TempButton); // We add this TempButton so we can scroll to the bottom of the _Panel.Controls
flowLayoutPanel.ScrollControlIntoView(TempButton); // We scroll to TempButton at the bottom of the _Panel.Controls
flowLayoutPanel.Controls.Remove(TempButton); // We remove TempButton
b.Dispose(); // clean up