请教各位在C#中vScrollBar的用法是怎样的呢???
具体的问题是想在picturebox中通过vScrollBar这个控件来拉动一张一张的显示图片,希望会的人能给出最理想的答案,谢谢!!!!!
//VScrollBarForPictureBox.cs using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace VScrollForImage { public class VScrollBarForPictureBox : VScrollBar { #region 全局字段 private List<string> _imagesPath; private PictureBox _pb; #endregion #region 公共属性 public PictureBox PictureContainer { set { _pb = value; if (_pb.Tag == null) return; _imagesPath = (List<string>) _pb.Tag; Maximum = _imagesPath.Count - 1; } } #endregion #region 重写方法 protected override void OnScroll(ScrollEventArgs se) { base.OnScroll(se); if (_imagesPath == null) return; _pb.Image = Image.FromFile(_imagesPath[se.NewValue]); } public override void Refresh() { base.Refresh(); if (_imagesPath == null) return; Maximum = _imagesPath.Count - 1; } #endregion } } //FormMain.cs using System.Collections.Generic; using System.Windows.Forms; namespace VScrollForImage { public partial class FormMain : Form { #region 构造函数 public FormMain() { InitializeComponent(); Pb.Tag = new List<string> { "0.jpg", "1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg" }; Vsb.PictureContainer = Pb; } #endregion } }