上传者: liudaheit
|
上传时间: 2019-12-21 20:10:02
|
文件大小: 23KB
|
文件类型: doc
WinForm 实现图片滚动
拖一个Timer和一个Panal控件
#region 把picbox绑定到Panal的最右边
private void GetImagePath(string strImagePath)
{
//1.在窗体中拖一个Panal控件
//2、定义一个PicBox用来存储图片,picbox的高度、宽度与Panal的高度相同
//3、实现图片从右向左滚动:picbox.left=panal.right-picbox.Width
_pb = new PictureBox();
_pb.Height = this.panel1.Height;
_pb.Width = this.panel1.Height;
//图片路径
Image imgs = Image.FromFile(strImagePath);
_pb.Image = imgs;
_pb.Left = this.panel1.Right - _pb.Width;
_CurIamgeTimes++;
this.panel1.Controls.Add(_pb);
}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{
try
{
//判断图片不为空
if (_pb != null)
{
//如果超出界限那么,就停止
if (_pb.Left - _pb.Left * _CurIamgeTimes - 100 < this.panel1.Left)
{
this.timer1.Stop();
_pb.Left = this.panel1.Left + _pb.Width * (_CurIamgeTimes - 1) - 2;
_pb = null;
}
else
_pb.Left -= 100;
}
}
catch { }
}