圖片管理器課程設(shè)計(jì)_第1頁
圖片管理器課程設(shè)計(jì)_第2頁
圖片管理器課程設(shè)計(jì)_第3頁
圖片管理器課程設(shè)計(jì)_第4頁
圖片管理器課程設(shè)計(jì)_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、學(xué) 號(hào) 天津城建大學(xué) 可視化編程 課程報(bào)告學(xué)生姓名班級(jí)成績(jī)計(jì)算機(jī)與信息工程學(xué)院目錄第1章 設(shè)計(jì)任務(wù)與目標(biāo)0第2章 設(shè)計(jì)方案12.1管理器結(jié)構(gòu)設(shè)計(jì)1第3章 設(shè)計(jì)實(shí)現(xiàn)23.1程序主窗體設(shè)計(jì)23.1.1主窗體代碼23.2程序目錄設(shè)計(jì)123.2.1目錄代碼123.3導(dǎo)入圖片窗體設(shè)計(jì)14 3.3.1導(dǎo)入圖片窗體代碼143.4所需的類代碼18第4章 設(shè)計(jì)結(jié)果與分析244.1設(shè)計(jì)分析計(jì)244.2設(shè)計(jì)結(jié)構(gòu)24第5章 總結(jié)心得25第1章 設(shè)計(jì)任務(wù)及目標(biāo)1.1 設(shè)計(jì)任務(wù)及目標(biāo)1、 設(shè)計(jì)圖片管理器,對(duì)圖片實(shí)現(xiàn)分目錄管理,用戶可以自行創(chuàng)建并刪除存放圖片的目錄,并且可以方便將各種圖片存放于相應(yīng)的目錄中。2、 可以對(duì)目錄

2、下的圖片以縮略圖的形式進(jìn)行瀏覽,方便用戶進(jìn)行查找圖片,并且在瀏覽過程中刪除一張或者多種圖片。3、 可以以實(shí)際大小或者適合窗體的大小對(duì)單張圖片瀏覽并切換到同目錄中的上一張或者下一張圖片進(jìn)行瀏覽。也可以對(duì)同目錄中的圖片以自動(dòng)播放形式進(jìn)行瀏覽,還可以調(diào)整播放時(shí)間間隔。0第2章 設(shè)計(jì)方案2.1 管理器結(jié)構(gòu)設(shè)計(jì) 通過對(duì)結(jié)構(gòu)的分析,以及考慮到要滿足的功能,將管理器分為如下幾個(gè)模塊。1. 主窗體:用來實(shí)現(xiàn)對(duì)圖片的瀏覽,刪除,導(dǎo)入,保存等功能。2. 目錄窗體:用來創(chuàng)建圖片的管理目錄,整理圖片。3. 導(dǎo)入圖片:用來將圖片導(dǎo)入目錄中,整理到相應(yīng)文件夾。 第3章 設(shè)計(jì)實(shí)現(xiàn)3.1程序的主窗體 1、設(shè)計(jì)程序的主窗體用來

3、瀏覽和查看圖片并且對(duì)圖片進(jìn)行管理。通過規(guī)劃,首先設(shè)計(jì)窗體頁面,然后添加相應(yīng)的控件。如下: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;/圖像自動(dòng)播放時(shí)間間隔2秒 ShowView();/處于瀏覽圖片狀態(tài) bgBrush = new SolidBrush(lvView.BackColor); statusStrip1.Items0.Visible = false;/狀態(tài)欄上的進(jìn)度為不可見 format.Alignment = StringAlignment.Center; try if (!Directory.Exists(path) Directory.CreateDirectory(path); catch (Except

7、ion ex) MessageBox.Show(ex.Message, "錯(cuò)誤", 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);/畫處于選中狀態(tài)的邊框 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;/改變鼠標(biāo)指針樣式 els

18、e /圖像小于顯示邊框是,則不允許拖動(dòng) canDrag = false; pbPic.Cursor = Cursors.Default; else /圖像使用PictureBox的大小顯示模式 canDrag = false;/設(shè)置禁止拖動(dòng)圖像狀態(tài) pbPic.Cursor = Cursors.Default; if (bmpInPb.Width > panel1.Width | bmpInPb.Height > panel1.Height) pbPic.Dock = DockStyle.Fill; pbPic.SizeMode = PictureBoxSizeMode.Zoom;

19、 else /圖像小于顯示邊框時(shí),按原尺寸顯示 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 ) /判斷是否鼠標(biāo)左鍵 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; /左右移動(dòng) 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; /上下移動(dòng) 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;/設(shè)置為禁止拖動(dòng)狀態(tài) private void tsbtnReturn_Click(object sender, EventArgs e) timer1.Stop();/停止計(jì)時(shí)器 pbPic.Image = null; if (bmpInPb != null) bmpInPb.Dispose();/釋放圖像 ShowView();/調(diào)整控件可見性 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 ("請(qǐng)選擇一個(gè)目錄再進(jìn)行刪除!", "消息",MessageBoxButtons .OK , MessageBoxIcon.Inf

27、ormation); return ; DialogResult dr=MessageBox .Show ("刪除目錄將導(dǎo)致該目錄下的圖片刪除", "并且該操作不可恢復(fù),是否真的要?jiǎng)h除“"+lstFolder .Text + "確認(rèn)",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+"”已經(jīng)被刪除!"/在狀態(tài)欄顯示提示 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) /刪除選中項(xiàng) ListViewItem item = lvView.SelectedItems 0; lvView.Items.Remove(item); folder.Remove(item.Text); catch (Exception ex) MessageBox.Show

30、(ex.Message, "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; finally lvView.EndUpdate(); private void tsBtnClose_Click(object sender, EventArgs e) Close(); 3.2 程序的目錄 創(chuàng)建目錄窗體,用于創(chuàng)建圖片的管理目錄。窗體控件如圖: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("請(qǐng)?jiān)谖谋究蛑休斎胍陆ǖ哪夸浢Q!", "消息",MessageBoxButtons.OK, MessageBoxIcon.Information); retur

33、n ; try string path=Application.StartupPath+"圖片目錄"+ TxtFolderName.Text; if (Directory.Exists(path ) MessageBox.Show("“"+TxtFolderName.Text+"”"+"目錄已經(jīng)存在,請(qǐng)輸入另一個(gè)名稱!", "消息對(duì)話框",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,"錯(cuò)誤", MessageBoxButtons.OK,MessageBoxIcon.Error); return; Close(); 3.3 導(dǎo)入圖片窗體 用于向目錄中導(dǎo)入圖片。如圖:3.3.1導(dǎo)入圖片窗體代碼如下: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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論