图片管理器课程设计_第1页
图片管理器课程设计_第2页
图片管理器课程设计_第3页
图片管理器课程设计_第4页
图片管理器课程设计_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、学 号 天津城建大学 可视化编程 课程报告学生姓名班级成绩计算机与信息工程学院目录第1章 设计任务与目标0第2章 设计方案12.1管理器结构设计1第3章 设计实现23.1程序主窗体设计23.1.1主窗体代码23.2程序目录设计123.2.1目录代码123.3导入图片窗体设计14 3.3.1导入图片窗体代码143.4所需的类代码18第4章 设计结果与分析244.1设计分析计244.2设计结构24第5章 总结心得25第1章 设计任务及目标1.1 设计任务及目标1、 设计图片管理器,对图片实现分目录管理,用户可以自行创建并删除存放图片的目录,并且可以方便将各种图片存放于相应的目录中。2、 可以对目录

2、下的图片以缩略图的形式进行浏览,方便用户进行查找图片,并且在浏览过程中删除一张或者多种图片。3、 可以以实际大小或者适合窗体的大小对单张图片浏览并切换到同目录中的上一张或者下一张图片进行浏览。也可以对同目录中的图片以自动播放形式进行浏览,还可以调整播放时间间隔。0第2章 设计方案2.1 管理器结构设计 通过对结构的分析,以及考虑到要满足的功能,将管理器分为如下几个模块。1. 主窗体:用来实现对图片的浏览,删除,导入,保存等功能。2. 目录窗体:用来创建图片的管理目录,整理图片。3. 导入图片:用来将图片导入目录中,整理到相应文件夹。 第3章 设计实现3.1程序的主窗体 1、设计程序的主窗体用来

3、浏览和查看图片并且对图片进行管理。通过规划,首先设计窗体页面,然后添加相应的控件。如下:3.1.1主窗体代码编写:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Collections;namespace 图片管理器3 public pa

4、rtial class MainForm : Form public MainForm() InitializeComponent(); private string path = Application.StartupPath + "图片目录" private Pen boundPen = new Pen(Color.Gainsboro); private Pen selPen = new Pen(Color.Blue, 3); private SolidBrush textBrush = new SolidBrush(Color.Black); private Soli

5、dBrush bgBrush; private StringFormat format = new StringFormat(); private Bitmap bmpInPb; private Point mousePoint = new Point(); private Point pbPoint = new Point(); private bool canDrag; private bool isDraging; private int bmpIndex; private void MainForm_Load(object sender, EventArgs e) lvView.Doc

6、k = DockStyle.Fill; tscbInterval.SelectedIndex = 1;/图像自动播放时间间隔2秒 ShowView();/处于浏览图片状态 bgBrush = new SolidBrush(lvView.BackColor); statusStrip1.Items0.Visible = false;/状态栏上的进度为不可见 format.Alignment = StringAlignment.Center; try if (!Directory.Exists(path) Directory.CreateDirectory(path); catch (Except

7、ion ex) MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; DirectoryInfo dir = new DirectoryInfo(path); foreach (DirectoryInfo d in dir.GetDirectories() Folder folder = new Folder(Application.StartupPath, d.Name); lstFolder.Items.Add(folder); private voi

8、d tsbtnCreatFolder_Click(object sender, EventArgs e) FrmCreatFolder frmCreatFolder = new FrmCreatFolder(this.lstFolder); try frmCreatFolder.ShowDialog(this); finally frmCreatFolder.Dispose(); private void tsbtnLoad_Click(object sender, EventArgs e) FrmLoadPic frmLoadPic = new FrmLoadPic(this.lstFold

9、er, this.statusStrip1); try if (frmLoadPic.ShowDialog(this) = DialogResult.OK) LoadToListView(); finally frmLoadPic.Dispose(); private void lvView_DrawItem(object sender, DrawListViewItemEventArgs e) if (lvView.Items.Count = 0) return; Graphics g = e.Graphics; Folder folder = (Folder)lstFolder.Selec

10、tedItem; Bitmap bmp = folder.GetThumnail(e.Item.Text); Rectangle bmpRect = Folder.GetRectFromBounds(bmp, e.Bounds); bmpRect.Offset(0, 1); Rectangle boundRect = Folder.GetRectFromBounds(101, 101, e.Bounds); Rectangle textRect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y + 109, e.Bounds.Width - 8, 16);

11、g.DrawRectangle(boundPen, boundRect); if (e.State & ListViewItemStates.Selected) != 0) g.DrawImage(bmp, bmpRect);/画图片的缩略图 boundRect.Inflate(1, 1); g.DrawRectangle(selPen, boundRect);/画处于选中状态的边框 else g.DrawImage(bmp, bmpRect); g.FillRectangle(bgBrush, textRect);/填充文字背景 g.DrawString(e.Item.Text, l

12、vView.Font, textBrush, textRect, format);/绘制文字 private void LoadToListView()/自定义方法 Folder folder = (Folder)lstFolder.SelectedItem; lvView.BeginUpdate(); lvView.Items.Clear(); if (!folder.IsLoaded) folder.LoadImage(); foreach (DictionaryEntry de in folder.bmps) lvView.Items.Add(string)de.Key); lvView

13、.EndUpdate(); private void lstFolder_SelectedIndexChanged(object sender, EventArgs e) if (lstFolder.SelectedItems.Count = 0) return; LoadToListView(); /让浏览图像缩略图所需控件可见 private void ShowView()/自定义方法 tsMain.Visible = true; lstFolder.Visible = true; splitter1.Visible = true; lvView.Visible = true; pbPic

14、.Visible = false; tsViewPic.Visible = false; /让浏览图像所需控件可见 private void ShowImage()/自定义方法 tsMain.Visible = false; lstFolder.Visible = false; splitter1.Visible = false; lvView.Visible = false; pbPic.Visible = true; tsViewPic.Visible = true; private void lvView_DoubleClick(object sender, EventArgs e) P

15、oint p = Control.MousePosition; p = lvView.PointToClient(p); ListViewHitTestInfo info = lvView.HitTest(p); ShowImage(); PaintImageInPb(info.Item.Text); bmpIndex = info.Item.Index; private void PaintImageInPb(string bmpName)/自定义方法 Folder folder = (Folder)lstFolder.SelectedItem; if (bmpInPb != null) b

16、mpInPb.Dispose(); bmpInPb = folder.GetImage(bmpName); statusStrip1.Items1.Text = "名称:" + bmpName + "尺寸:" + bmpInPb.Width.ToString() + "×" + bmpInPb.Height.ToString(); pbPic.Image = bmpInPb; MatchImage(); private void MatchImage()/自定义方法 if (tsbtnNormol.Checked) /正常显

17、示模式 pbPic.Dock = DockStyle.None; pbPic.SizeMode = PictureBoxSizeMode.AutoSize; pbPic.Left = (panel1.Width - pbPic.Width) / 2; pbPic.Top = (panel1.Height - pbPic.Height) / 2; if (pbPic.Width > panel1.Width | pbPic.Height > panel1.Height) canDrag = true; pbPic.Cursor = Cursors.Hand;/改变鼠标指针样式 els

18、e /图像小于显示边框是,则不允许拖动 canDrag = false; pbPic.Cursor = Cursors.Default; else /图像使用PictureBox的大小显示模式 canDrag = false;/设置禁止拖动图像状态 pbPic.Cursor = Cursors.Default; if (bmpInPb.Width > panel1.Width | bmpInPb.Height > panel1.Height) pbPic.Dock = DockStyle.Fill; pbPic.SizeMode = PictureBoxSizeMode.Zoom;

19、 else /图像小于显示边框时,按原尺寸显示 pbPic.Dock = DockStyle.None; pbPic.SizeMode = PictureBoxSizeMode.AutoSize; pbPic.Left = (panel1.Width - pbPic.Width) / 2; pbPic.Top = (panel1.Height - pbPic.Height) / 2; private void tsbtnShowMode_Click(object sender, EventArgs e) ToolStripButton btn = (ToolStripButton)sender

20、; if (btn .Checked ) return ; tsbtnNormol.Checked =false ; tsbtnMatch.Checked=false ; btn .Checked =true ; MatchImage (); private void pbPic_MouseDown(object sender, MouseEventArgs e) if (e.Button !=MouseButtons .Left ) /判断是否鼠标左键 return ; isDraging=true ; mousePoint.X =e.X ; mousePoint.Y=e.Y; pbPoin

21、t.X =pbPic.Left ; pbPoint.Y=pbPic.Top; private void pbPic_MouseMove(object sender, MouseEventArgs e) if (!isDraging | !canDrag) return; /左右移动 int x = pbPic.Left; if (pbPic.Width > panel1.Width) x += e.X - mousePoint.X; if (x > 0) x = 0; else if (x + pbPic.Width < panel1.Width) x = panel1.Wi

22、dth - pbPic.Width; /上下移动 int y = pbPic.Top; if (pbPic.Height > panel1.Height ) y += e.Y - mousePoint.Y; if (y > 0) y = 0; else if (y + pbPic.Height < panel1.Height ) y = panel1.Height - pbPic.Height ; pbPic.Left = x; pbPic.Top = y; private void pbPic_MouseUp(object sender, MouseEventArgs e)

23、 if (e.Button != MouseButtons.Left) return; isDraging = false;/设置为禁止拖动状态 private void tsbtnReturn_Click(object sender, EventArgs e) timer1.Stop();/停止计时器 pbPic.Image = null; if (bmpInPb != null) bmpInPb.Dispose();/释放图像 ShowView();/调整控件可见性 private void tsbtnPeriod_Click(object sender, EventArgs e) if

24、(bmpIndex = 0) bmpIndex = lvView.Items.Count - 1; else bmpIndex-; ListViewItem item = lvView.ItemsbmpIndex; PaintImageInPb (item .Text); private void tsbtnNext_Click(object sender, EventArgs e) if (bmpIndex =lvView.Items .Count -1) bmpIndex = 0; else bmpIndex+; ListViewItem item = lvView.ItemsbmpInd

25、ex; PaintImageInPb (item .Text); private void tsbtnAutoPlay_Click(object sender, EventArgs e) timer1.Enabled = !timer1.Enabled; tsbtnAutoPlay.Checked = timer1.Enabled; private void tscbInterval_SelectedIndexChanged(object sender, EventArgs e) timer1.Interval = (int)(Math.Pow(2, tscbInterval.Selected

26、Index) * 1000); private void timer1_Tick(object sender, EventArgs e) tsbtnNext_Click(null, null); private void tsbtnDelFolder_Click(object sender, EventArgs e) if (lstFolder .SelectedItems .Count=0) MessageBox.Show ("请选择一个目录再进行删除!", "消息",MessageBoxButtons .OK , MessageBoxIcon.Inf

27、ormation); return ; DialogResult dr=MessageBox .Show ("删除目录将导致该目录下的图片删除", "并且该操作不可恢复,是否真的要删除“"+lstFolder .Text + "确认",MessageBoxButtons .YesNo ,MessageBoxIcon .Question ); string delFolderName=""/用于存放被删除目录的名称 if (dr = DialogResult.Yes) lvView.Clear(); delFolde

28、rName = lstFolder.Text; (Folder)lstFolder.SelectedItem).RemoveAll(); lstFolder.Items.Remove(lstFolder.SelectedItem); statusStrip1.Items1.Text="目录“"+delFolderName+"”已经被删除!"/在状态栏显示提示 private void tsbtnDel_Click(object sender, EventArgs e) if (lstFolder.SelectedItems.Count = 0 | lvV

29、iew.Visible = false) return; Folder folder = (Folder)lstFolder.SelectedItem; try lvView.BeginUpdate();/禁止ListView的刷新 while (lvView.SelectedItems .Count > 0) /删除选中项 ListViewItem item = lvView.SelectedItems 0; lvView.Items.Remove(item); folder.Remove(item.Text); catch (Exception ex) MessageBox.Show

30、(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; finally lvView.EndUpdate(); private void tsBtnClose_Click(object sender, EventArgs e) Close(); 3.2 程序的目录 创建目录窗体,用于创建图片的管理目录。窗体控件如图:3.2.1目录代码如下:using System;using System.Collections.Generic;using System.ComponentModel;u

31、sing System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace 图片管理器3 public partial class FrmCreatFolder : Form public FrmCreatFolder() InitializeComponent(); public FrmCreatFolder(ListBox lst) InitializeComponent(); lstFolder = lst; p

32、rivate ListBox lstFolder; private void btnCancel_Click(object sender, EventArgs e) Close(); private void btnOK_Click(object sender, EventArgs e) if (TxtFolderName.Text="") MessageBox.Show("请在文本框中输入要新建的目录名称!", "消息",MessageBoxButtons.OK, MessageBoxIcon.Information); retur

33、n ; try string path=Application.StartupPath+"图片目录"+ TxtFolderName.Text; if (Directory.Exists(path ) MessageBox.Show("“"+TxtFolderName.Text+"”"+"目录已经存在,请输入另一个名称!", "消息对话框",MessageBoxButtons.OK, MessageBoxIcon.Error); return; Directory.CreateDirectory(

34、path); Folder folder = new Folder(Application.StartupPath, TxtFolderName.Text); lstFolder.Items. Add(folder ); catch (Exception ex) MessageBox.Show(ex.Message,"错误", MessageBoxButtons.OK,MessageBoxIcon.Error); return; Close(); 3.3 导入图片窗体 用于向目录中导入图片。如图:3.3.1导入图片窗体代码如下:using System;using Syst

35、em.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Collections;using System.IO;namespace 图片管理器3 public partial class FrmLoadPic : Form public FrmLoadPic() InitializeComponent(); public

36、FrmLoadPic(ListBox lst, StatusStrip sta) InitializeComponent(); lstFolder = lst; staMsg = sta; openFileDialogSelPic.Filter = "图像文件(*.BMP;*JPG;*.GIF;" + "*.jpeg;*.ico)|*.BMP;*JPG;*.GIF;*.jpeg;*.ico" private ListBox lstFolder; private StatusStrip staMsg; private void FrmLoadPic_Load(object sender, EventArgs e) foreach (object o in lstFolder.Items) cbFolder.Items.Add(o); if (lstFolder.SelectedItems.Count != 0) cbFolder.SelectedIndex = lstFolder.SelectedIndex; else cbFolder.SelectedIndex = 0; privat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论