续上一个文章(晨曦CZB)
后台代码:
#region 局部变量public Form1(){InitializeComponent();this.Load += (s, e) =>{DataShow();ControlEvent();};}#endregion#region 绑定数据/// <summary>/// 绑定数据/// </summary>private void DataShow(){var path = Application.StartupPath + @"\Image";var files = new DirectoryInfo(path).GetFiles();var data = files.Select(d =>{this.imageSlider1.Images.Add(Image.FromFile(d.FullName));return new { Name = d.Name, Image = Image.FromFile(d.FullName), Paths = d.FullName };});this.gridControl1.BeginUpdate();this.gridControl1.DataSource = data;this.gridControl1.EndUpdate();}#endregion#region 控件的委托事件/// <summary>/// 控件的委托事件/// </summary>private void ControlEvent(){/*卡片的点击事件*/this.layoutView1.CardClick += (s, e) =>{if (e.Button == MouseButtons.Left)this.imageSlider1.CurrentImageIndex = e.Card.RowHandle;};this.sbtnFirst.Click += (s, e) =>{this.imageSlider1.SlideFirst();};this.sbtnPrev.Click += (s, e) =>{this.imageSlider1.SlidePrev();};this.sbtnNext.Click += (s, e) =>{this.imageSlider1.SlideNext();};this.sbtnLast.Click += (s, e) =>{this.imageSlider1.SlideLast();};this.sbtnClose.Click += (s, e) =>{this.Close();};this.sbtnDownload.Click += (s, e) =>{var path = (string)this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Paths");var name = this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Name");SaveFileDialog sf = new SaveFileDialog();sf.Title = "选择保存文件路径";sf.Filter = "图像文件(*.jpg)|*.jpg;";sf.FileName = name.ToString();sf.AddExtension = true;/*自动添加扩展名*/if (sf.ShowDialog() == DialogResult.OK){File.Copy(path, sf.FileName, true);//目录重命名见下面代码}};}#endregion