如何自动滚动到VScrollBar的底部

时间:2014-02-03 09:44:54

标签: c# winforms

在fDisplaySMSList表单中,我有一个pictureBox和VScrollBar

Image1

每个数据都在PictureBox中,VScrollBar不会自动滚动到底部的新数据。如何在VScrollBar中自动滚动到底部?

------------------------修改

我有一张短信,就像这样,

enter image description here

当新的收件箱或撰写进入表单时,滚动始终位于顶部,此处为pict。

enter image description here

问题是当我发送或接收这样的消息时,如何形成VScrollBar,

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试设置ScrollBar.Value属性

还可以尝试为要滚动的最后一个ListViewItem调用ListView.EnsureVisible

答案 1 :(得分:0)

ScrollBar.Value默认为0,表示左上角。 您可以将其设置为您想要的任何可能的位置,例如ScrollBar.Bottom

另一方面,如果你想在这里移动图片时移动它,你可以找到一个例子 http://msdn.microsoft.com/es-es/library/system.windows.forms.scrollbar.value(v=vs.110).aspx

private void HandleScroll(Object sender, ScrollEventArgs e)
{
//Create a graphics object and draw a portion of the image in the PictureBox.
Graphics g = pictureBox1.CreateGraphics();

int xWidth = pictureBox1.Width;
int yHeight = pictureBox1.Height;

int x;
int y;

if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
    x = e.NewValue;
    y = vScrollBar1.Value;
}
else //e.ScrollOrientation == ScrollOrientation.VerticalScroll
{
    y = e.NewValue;
    x = hScrollBar1.Value;
}

g.DrawImage(pictureBox1.Image,
  new Rectangle(0, 0, xWidth, yHeight),  //where to draw the image
  new Rectangle(x, y, xWidth, yHeight),  //the portion of the image to draw
  GraphicsUnit.Pixel);

pictureBox1.Update();
相关问题