问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Drawing.Imaging;usingSystem.Drawing.Drawing2D;namespace图像放大{publicpartialclassForm1:Form{CursormyCursor=newCursor(@"C:WINDOWSCursorscross_r.cur");//自定义鼠标ImagemyImage;publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){//设置文件的类型openFileDialog1.Filter="*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";openFileDialog1.ShowDialog();//打开文件对话框myImage=System.Drawing.Image.FromFile(openFileDialog1.FileName);//根据文件的路径和名称实例化Image类pictureBox1.Image=myImage;//显示图片pictureBox1.Height=myImage.Height;//设置控件的高度pictureBox1.Width=myImage.Width;//设置控件的宽度}privatevoidpictureBox1_MouseMove(objectsender,MouseEventArgse){try{Cursor.Current=myCursor;//定义鼠标Graphicsgraphics=pictureBox1.CreateGraphics();//实例化pictureBox1控件的Graphics类//声明两个Rectangle对象,分别用来指定要放大的区域和放大后的区域RectanglesourceRectangle=newRectangle(e.X-10,e.Y-10,20,20);//要放大的区域RectangledestRectangle=newRectangle(e.X-20,e.Y-20,40,40);//调用DrawImage方法对选定区域进行重新绘制,以放大该部分graphics.DrawImage(myImage,destRectangle,sourceRectangle,GraphicsUnit.Pixel);}catch{}}privatevoidpictureBox1_Click(objectsender,EventArgse){}}}怎么运行后却不能放大图片啊?求大神解决!!!另外privatevoidpictureBox1_MouseMove(objectsender,MouseEventArgse)中的MouseMove是自己敲出来,还按哪个控件?
解决方案
解决方案二:
解决方案三:
你需要绑定下,在Form_Load里面写this.MouseMove+=pictureBox1_MouseMove