计算机上机实验报告(2010——2011学年第2学期)班级:软件101姓名:罗今学号:201000514120课程名称:面向对象设计C#指导教师:张慎武实验名称:GDI与图形图像实验序号:7实验日期:2012-5-26实验成绩:要求:1.实验内容部分主要是对本次实习所做工作的理解,即主要实现了什么功能,主要思路。不要过于简略,也不能罗列程序。2.源程序请单独提交,不要附在实习报告中。3.报告要注意简练,但能完整表达自己的意图,不要刻意追求篇幅。一、实验目的及要求(本次上机实践所涉及并要求掌握的知识点)。1.深入理解网络通信的基本技术和方法。2.进一步理解常用网络协议的基本概念。3.掌握基本的网络通信的程序设计,熟练应用套接字和常用的网络通信类。二、实验环境(本次上机实践所使用的平台和相关软件)。软件:WindowsXP系统+VisualStudio2010三、实验内容(1)设计一个根据鼠标来绘制矩形的程序,即当按下鼠标左键并拖动至某个位置后释放鼠标时,可根据按下鼠标时的第1个点和释放鼠标时的第2个点来确定并绘制矩形。(2)设计一个动态翻看图片的程序,包含两个按钮(“上一张”,”下一张”),图片显示是可以是”上下对接”,“左右拉伸”,“反转”以及“中间想两边拉伸”等动态效果。(3)设计一个简单的20*20棋盘格的手动移子的五子棋程序。四、实验步骤及结果第一个程序(绘制矩形):(1)窗口控件设计:(2)代码设计:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace绘制矩形{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();g=this.pictureBox1.CreateGraphics();}Graphicsg;intx=0;inty=0;boolblDraw=false;privatevoidpictureBox1_MouseDown(objectsender,MouseEventArgse){x=e.X;y=e.Y;blDraw=true;}privatevoidpictureBox1_MouseUp(objectsender,MouseEventArgse){if(blDraw){Penp=newPen(Color.Blue,2);if(xe.X&&ye.Y)g.DrawRectangle(p,x,y,System.Math.Abs(e.X-x),System.Math.Abs(e.Y-y));if(xe.X&&ye.Y)g.DrawRectangle(p,x,e.Y,System.Math.Abs(e.X-x),System.Math.Abs(e.Y-y));if(xe.X&&ye.Y)g.DrawRectangle(p,e.X,y,System.Math.Abs(e.X-x),System.Math.Abs(e.Y-y));if(xe.X&&ye.Y)g.DrawRectangle(p,e.X,e.Y,System.Math.Abs(e.X-x),System.Math.Abs(e.Y-y));}blDraw=false;}}}第二个程序(动态翻看图片):(1)窗口控件设计:(2)代码设计:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace动态翻看图片{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}string[]files;stringfile;stringpfile;stringprefile;stringnextfile;publicstringGetDirPath(stringfilePath)//得到上级目录{stringdirPath=;inti;string[]str=filePath.Split('\\');for(i=0;istr.Length-1;i++){dirPath+=str[i]+\\;}returndirPath;}privatevoidbutton3_Click(objectsender,EventArgse){OpenFileDialogofd1=newOpenFileDialog();ofd1.Filter=Bitmap文件(*.bmp)|*.bmp|所有适合文件(*.bmp/*.jpg/*.gif)|*.*|Jpeg文件(*.jepg)|*.jpg;ofd1.FilterIndex=2;ofd1.RestoreDirectory=true;if(DialogResult.OK==ofd1.ShowDialog()){BitmapSourceBitmap=newBitmap(ofd1.FileName);BitmapMyBitmap=newBitmap(SourceBitmap,this.pictureBox1.Width,this.pictureBox1.Height);try{pictureBox1.Image=MyBitmap;}catch(Exception){MessageBox.Show(该文件不是图形图像文件,无法显示浏览!,错误提示);}file=ofd1.FileName;pfile=GetDirPath(file);//获取上级目录名}}privatevoidbutton1_Click(objectsender,EventArgse){files=Directory.GetFiles(pfile);for(inti=0;ifiles.Length;i++){if(file==files[i])if(i-1!=-1){prefile=files[i-1];break;}else{prefile=files[i];break;}}try{BitmapSourceBitmap=newBitmap(prefile);BitmapMyBitmap=newBitmap(SourceBitmap,this.pictureBox1.Width,this.pictureBox1.Height);pictureBox1.Image=MyBitmap;}catch(Exception){MessageBox.Show(该文件不是图形图像文件,无法显示浏览!,错误提示);}file=prefile;}privatevoidbutton2_Click(objectsender,EventArgse){files=Directory.GetFiles(pfile);for(inti=0;ifiles.Length;i++){if(file==files[i]){if(i+1files.Length){nextfile=files[i+1];break;}else{nextfile=files[i];break;}}}try{BitmapSourceBitmap=newBitmap(nextfile);BitmapMyBitmap=newBitmap(SourceBitmap,this.pictureBox1.Width,this.pictureBox1.Height);pictureBox1.Image=MyBitmap;}catch(Exception){MessageBox.Show(该文件不是图形图像文件,无法显示浏览!,错误提示);}file=nextfile;}privatevoidbutton4_Click(objectsender,EventArgse){try{intwidth=this.pictureBox1.Width;//图像宽度intheight=this.pictureBox1.Height;//图像高度Bitmapbit1=newBitmap(width,height/2-1);Graphicsg_bit1=Graphics.FromImage(bit1);Graphicsg=this.pictureBox1.CreateGraphics();g_bit1.DrawImage(this.pictureBox1.Image,newRectangle(0,0,width,height/2-1),newRectangle(0,0,width,height/2-1),GraphicsUnit.Pixel);//获取picturebox1中的上半部分图像bit1.RotateFlip(RotateFlipType.Rotate180FlipX);for(inty=0;y=Height/2-1;y++){g.DrawImage(bit1,0,0,width,y);System.Threading.Thread.Sleep(3);}}catch(Exception){MessageBox.Show(不能载入图像,信息提示);}}privatevoidbutton5_Click(objectsender,EventArgse){BitmapMyBitmap=newBitmap(this.pictureBox1.Image);intiWidth=this.pictureBox1.Width;intiHeight=this.pictureBox1.Height;Graphicsg=this.pictureBox1.CreateGraphics();g.Clear(Color.Gray);for(inty=0;y=iHeight;y++){g.DrawImage(MyBitmap,0,0,iWidth,y);System.Threading.Thread.Sleep(3);}}privatevoidbutton6_Click(objectsender,EventArgse){BitmapMyBitmap=newBitmap(this.pictureBox1.Image);intiWidth=this.pictureBox1.Width;intiHeight=this.pictureBox1.Height;Graphicsg=this.pictureBox1.CreateGraphics();g.Clear(Color.Gray);for(intx=0;x=iWidth;x++){g.DrawImage(MyBitmap,0,0,x,iHeight);System.Threading.Thread.Sleep(3);}}privatevoidbutton7_Click(objectsender,EventArgse){BitmapMyBitmap=newBitmap(this.pictureBox1.Image);intiWidth=this.pictureBox1.Width;intiHeight=this.pictureBox1.Height;Graphicsg=this.pictureBox1.CreateGraphics();g.Clear(Color.Gray);for(inty=0;y=iWidth/2;y++){RectangleDestRect=newRectangle(iWidth/2-y,0,2*y,iHeight);Rectang