因这学期选修了.net,而这门课每一个实验跟综合性实验没什么不同,都得做成一个应用程序。昨晚写完了这个实验的报告就顺便贴上来了。

首先上几个截图:

程序运行主窗口:

 

双击缩略图之后创建图片查看器:

 

 

1. 顺时针、逆时针

 

 

实际大小(允许使用鼠标拖拽):

 

屏幕截图:

选定区域

 

双击区域弹出保存窗口:

 

缩略图核心代码:


 
   
  1. private void ThreadProcSafe(object arg) 
  2.            { 
  3.                this.CreateMyListView((string[])arg); 
  4.            } 
  5.            private void CreateMyListView(string[] arg) 
  6.            { 
  7.                if (listView1 == null
  8.                    return
  9.                if (this.listView1.InvokeRequired) 
  10.                { 
  11.                    this.Invoke(new CreateMyListViewCallback(this.CreateMyListView), new object[] { arg }); 
  12.                } 
  13.                else 
  14.                { 
  15.                    string[] path = arg; 
  16.                    listView1.View = View.LargeIcon; 
  17.                    listView1.Items.Clear(); 
  18.                    ImageList p_w_picpathListLarge = new ImageList(); 
  19.                    listView1.LargeImageList = p_w_picpathListLarge; 
  20.                    p_w_picpathListLarge.ImageSize = new System.Drawing.Size(120, 112); 
  21.                    this.Cursor = Cursors.WaitCursor; 
  22.                    for (int i = 0; i < path.Length; i++) 
  23.                    { 
  24.                        try 
  25.                        { 
  26.                            p_w_picpathListLarge.Images.Add(System.Drawing.Image.FromFile(path[i])); 
  27.                            this.listView1.Items.Add(path[i], i); 
  28.                        } 
  29.                        catch { } 
  30.                    } 
  31.                    this.Cursor = Cursors.AppStarting; 
  32.                } 
  33.            } 

 

 

拖拽功能实现核心代码:

 

 
   
  1. private void moveRepaint(myPoint po) 
  2.         { 
  3.  
  4.             Graphics g = this.pictureBox1.CreateGraphics(); 
  5.             int width = this.pictureBox1.Width; 
  6.             int height = this.pictureBox1.Height; 
  7.             Rectangle destPara = new Rectangle(pic.getActual().Width, pic.getActual().Height, width, height); 
  8.             // Create rectangle for source p_w_picpath. 
  9.             Rectangle srcRect = new Rectangle(po.x, po.y, width, height); 
  10.             GraphicsUnit units = GraphicsUnit.Pixel; 
  11.             g.DrawImage(this.pictureBox1 .Image, destPara, srcRect, units); 
  12.         } 
  13.  
  14.         private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
  15.         { 
  16.  
  17.             if (e.Button == MouseButtons.Left&&!flag) 
  18.             { 
  19.                 mouseDown = true
  20.                 mousePoint.x = e.X; 
  21.                 mousePoint.y = e.Y; 
  22.  
  23.             } 
  24.         } 
  25.  
  26.         private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
  27.         { 
  28.  
  29.             if (mouseDown) 
  30.             { 
  31.  
  32.                 sft.x = mousePoint.x - e.X; 
  33.                 sft.y = mousePoint.y - e.Y; 
  34.                 this.moveRepaint(pic.getChange(sft)); 
  35.             } 
  36.  
  37.         } 
  38.  
  39.         private void pictureBox1_MouseUp(object sender, MouseEventArgs e) 
  40.         { 
  41.             if (!flag) 
  42.             { 
  43.                 mouseDown = false
  44.                 sft.x = mousePoint.x - e.X; 
  45.                 sft.y = mousePoint.y - e.Y; 
  46.                 pic.setLocalPoin(pic.getChange(sft)); 
  47.             } 
  48.         } 

 

幻灯片功能实现核心代码:

 

 

 
   
  1. public partial class PowerPoint : Form 
  2.     { 
  3.         private Bitmap myBitmap; 
  4.         int index = 0; 
  5.         string[] files; 
  6.         public PowerPoint(string[] files) 
  7.         { 
  8.             this.files = files; 
  9.             InitializeComponent(); 
  10.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
  11.             this.WindowState = System.Windows.Forms.FormWindowState.Maximized; 
  12.             this.TopMost = true ; 
  13.             this.timer1.Enabled = true
  14.         } 
  15.         private void timer2_Tick(object sender, EventArgs e)  
  16.         { 
  17.             ThreadStart threadStart = new ThreadStart(showPicture); 
  18.             Thread thread = new Thread(threadStart); 
  19.             thread.Start(); 
  20.  
  21.         } 
  22.  
  23.         public void showPicture()  
  24.         { 
  25.             if (this.index < files.Length) 
  26.             { 
  27.                 myBitmap = new Bitmap(files[this.index]); 
  28.                 if (this.pictureBox1.Image != nullthis.pictureBox1.Image.Dispose(); 
  29.                 this.pictureBox1.Image = myBitmap; 
  30.                 this.index++; 
  31.             } 
  32.             else 
  33.                 this.index=0; 
  34.         } 
  35.  
  36.  
  37.         private void Form_Click(object sender, EventArgs e) 
  38.         { 
  39.             this.Close(); 
  40.         } 
  41.  
  42.  
  43.     } 

 

屏幕截图实现核心代码:

 

 

 
   
  1. void catcher_DoubleClick(object sender, EventArgs e) 
  2.         { 
  3.             this.catcher.TransparencyKey = this.BackColor; 
  4.             Bitmap bmpCatched = new Bitmap(this.catcher.Width, this.catcher.Height); 
  5.             Graphics g = Graphics.FromImage(bmpCatched); 
  6.             Point locat = new Point(this.catcher.Location.X); 
  7.             g.CopyFromScreen(this.catcher.Location, new Point(0, 0), this.catcher.ClientRectangle.Size, CopyPixelOperation.SourceCopy); 
  8.             //Clipboard.SetImage(bmpCatched); 
  9.             this.saveFileDialog1 = new SaveFileDialog(); 
  10.             saveFileDialog1.Filter = "Image File(*.jpg;)|*.jpg;|Image File(*.bmp;)|*.bmp;"
  11.             saveFileDialog1.ShowDialog(); 
  12.  
  13.                  //If the file name is not an empty string open it for saving. 
  14.                 if (saveFileDialog1.FileName != ""
  15.                 { 
  16.                     System.IO.FileStream fs = 
  17.                        (System.IO.FileStream)saveFileDialog1.OpenFile(); 
  18.                     switch (saveFileDialog1.FilterIndex) 
  19.                     { 
  20.                         case 1: 
  21.                          bmpCatched.Save(fs, 
  22.                            System.Drawing.Imaging.ImageFormat.Jpeg); 
  23.                         break
  24.  
  25.                         case 2: 
  26.                             bmpCatched.Save(fs, 
  27.                            System.Drawing.Imaging.ImageFormat.Bmp); 
  28.                         break
  29.  
  30.                      
  31.                     } 
  32.  
  33.                     fs.Close(); 
  34.                 } 
  35.                 this.catcher.Close(); 
  36.                 g.Dispose(); 
  37.                 this.catcher.Dispose(); 
  38.                 this.Close(); 
  39.         } 

部分功能实现思路:

 

1. 图片查看窗口中实际大小”的功能通过使用Graphics.DrawImage(Image, destRectangle, srcRectangle, GraphicsUnit)的这个重载方法实现,destRectangle是确定画布的大小,里面可以自定义画布起始的坐标,长度和宽度;srcRectangle定义的是需要绘制的原图片的哪一个部分,里面有起始的坐标和图片的长度和宽度。

2. 在按下“实际大小”按钮之后,如果图片实际的分辨率比屏幕的分辨率大,则可以对图片进行拖拽,图片默认显示从(0,0)坐标开始到pictureBox的长和宽大小的部分。当进入可以拖拽的的pictureBox的区域,鼠标的指针会变成一个hand的形状,离开后恢复。

3. 幻灯片的功能通过新建一个没有边界,不显示状态栏图标的窗口完成,整个效果如同全屏显示图片。新建的窗口包含一个timer,里面设定Interval1500,每过1500毫秒显示下一张图片,图片是循环显示的,通过鼠标点击结束幻灯片的播放。

4. 屏幕截图功能实现思路:

a) 首先新建一个没有边界,不显示状态栏图标的窗口formback

b) formback的边界设置为系统窗口的边界

c) formback的背景图片设置为系统当前状态。获取系统当前状态的方式:通过使用Graphics.CopyFromScreen函数实现,起始位置(00),长度和宽度为屏幕的大小。

d)   当鼠标左键按下时新建另一个窗口,一个没有边界没有状态栏图标的窗口formcatcher。通过鼠标的移动,不断改变窗口的大小,当鼠标左键松开,formcatcher最终生成。鼠标滑过的地方有一层乳白色的半透明窗口,双击formcatcher,把窗体透明区域的颜色设置成为完全透明。

e)   再次使用Graphics.CopyFromScreen函数,截取由formcatcher选中的区域。弹出保存文件的窗口,填写文件名,保存文件。

 

 

遗憾的是还剩下一些Bug没有解决,那就是在图片查看窗口中,当图片经过旋转操作之后如果再使用实际大小”的拖拽功能,图片可以被拖出图片窗口外面,原因很简单,因为重画的时候大小依然按照旋转前的图片的大小。

最后,需要说明的是这个程序中主窗口的系统文件树是在原始版是在下面这个地址找到的,后面我进行了一些改动:

http://www.cnblogs.com/peterzb/archive/2009/06/08/1499131.html

里面对treeView进行了很详尽的讲解。

还有,屏幕截图功能的实现是在下面地址中的qq截屏软件的基础上进行改进的:

http://www.cnblogs.com/zhouyinhui/archive/2006/06/27/437017.html

非常感谢上面的两位

因为实验还没有提交评分,所以程序的源码就先不上,先上一个程序的运行版,源代码后面会补上

 今天修复了上面所说的bug,重新上传运行的程序

 最后,上传上源码,因为后面没有时间做,很多bug没有调,希望多多包涵