我有一個flowlayoutpanel
在我的winform中動態添加圖像。我想vertical scroll bar
總是在底部顯示最後添加的圖像。我怎樣才能做到這一點? 我總是滾動到垂直滾動條的底部
AutoScroll = true
FLow Direction = Top Down
Wrap Content = False
我有一個flowlayoutpanel
在我的winform中動態添加圖像。我想vertical scroll bar
總是在底部顯示最後添加的圖像。我怎樣才能做到這一點? 我總是滾動到垂直滾動條的底部
AutoScroll = true
FLow Direction = Top Down
Wrap Content = False
滾動容器控件,比如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);
這是一種強制的最後控制進入視野。
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
強制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
這是正確的做法:
MyControl uct = new MyControl();
uct.Parent = flowLayoutPanel;
this.ActiveControl = uct;
if (flowLayoutPanel.VerticalScroll.Visible)
{
flowLayoutPanel.ScrollControlIntoView(uct);
}
日Thnx。它做了這項工作。我可以使用這兩種方法,因爲我有linkbox下面的picturebox。 – umuieme