1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSystem.Threading;Ten One namespaceTest A { - Public Partial classForm2:form - { the Private BOOLBlisdrawrectangle =true; - PrivatePoint Ptbegin =NewPoint (); - Thread Thdraw; - Delegate voidMydrawrectangel (); + Mydrawrectangel Mydraw; - PublicForm2 () + { A InitializeComponent (); at } - - Private voidPicturebox1_paint (Objectsender, PaintEventArgs e) - { - if(Blisdrawrectangle) - { inE.graphics.drawrectangle (NewPen (Brushes.black,1), ptbegin.x, PTBEGIN.Y, -, -); - } to } + - Private voidForm2_load (Objectsender, EventArgs e) the { *Mydraw =NewMydrawrectangel (showdrawrectangle); $Thdraw =NewThread (Run);Panax Notoginseng Thdraw.start (); - } the Private voidRun () + { A while(true) the { + if(pictureBox1.Image! =NULL) - { $ This. BeginInvoke (Mydraw); $ } -Thread.Sleep ( -); - } the } - Private voidShowdrawrectangle ()Wuyi { theRectangle rec =NewRectangle (ptbegin.x * pictureBox1.Image.Size.Width/460, -PTBEGIN.Y * PictureBox1.Image.Size.Height/ -, -* PictureBox1.Image.Size.Width/460, Wu -* PictureBox1.Image.Size.Height/ -); -Graphics g =picturebox2.creategraphics (); About g.drawimage (pictureBox1.Image, Picturebox2.clientrectangle, REC, graphicsunit.pixel); $ G.flush (); - } - - Private voidPicturebox1_mouseleave (Objectsender, EventArgs e) A { +Blisdrawrectangle =false; the Picturebox1.refresh (); - } $ the Private voidPicturebox1_mouseenter (Objectsender, EventArgs e) the { theBlisdrawrectangle =true; the } - in Private voidPicturebox1_mousemove (Objectsender, MouseEventArgs e) the { the if(E.x- -<=0) About { thePtbegin.x =0; the } the Else if(Picturebox1.size.width-e.x <= -) + { -ptbegin.x = PictureBox1.Size.Width- -; the }Bayi Else the { theptbegin.x = e.x- -; - } - the if(E.y- -<=0) the { thePTBEGIN.Y =0; the } - Else if(picturebox1.size.height-e.y<= -) the { thePTBEGIN.Y = PictureBox1.Size.Height- -; the }94 Else the { thePTBEGIN.Y = e.y- -; the }98 Picturebox1.refresh (); About } - }101}
View Code
C # winfrom Magnifier feature