Previous Article: C # software development instance. customized screen tool (6) add Configuration Management Function
Because a part may need to be captured accurately, the magnifier function is required so that the position can be located more easily.
Add PictureBox and set the name attribute to "pictureBox_zoom ";
Add the following code to the "Form1_Load" event handler:
// Set the magnifier size this. pictureBox_zoom.Width = this. ZoomBoxWidth; this. pictureBox_zoom.Height = this. ZoomBoxHeight;
Add the code in the "ExitCutImage" method:
Add the code to the "Form1_MouseUp" event handler:
Add the code at the end of the else condition of the "ShowForm" method:
if (this.ZoomBoxVisible) { UpdateCutInfoLabel(UpdateUIMode.ShowZoomBox); this.pictureBox_zoom.Show(); }
Add the following code at the end of the UpdateCutInfoLabel function:
if (this.pictureBox_zoom.Visible || (updateUIMode & UpdateUIMode.ShowZoomBox) != UpdateUIMode.None) { Point zoomLocation = new Point(MousePosition.X + 15, MousePosition.Y + 22); if (zoomLocation.Y + this.pictureBox_zoom.Height > this.Height) { if (zoomLocation.X + this.pictureBox_zoom.Width > this.Width) { zoomLocation = new Point(MousePosition.X - this.pictureBox_zoom.Width - 10, MousePosition.Y - this.pictureBox_zoom.Height - 10); } else { zoomLocation = new Point(MousePosition.X + 15, MousePosition.Y - this.pictureBox_zoom.Height - 15); } } else { if (zoomLocation.X + this.pictureBox_zoom.Width > this.Width) { zoomLocation = new Point(MousePosition.X - this.pictureBox_zoom.Width - 15, MousePosition.Y); } } this.pictureBox_zoom.Location = zoomLocation; if (!this.pictureBox_zoom.Visible) { this.pictureBox_zoom.Show(); } }
Add the following code to the Form1_KeyUp event handler:
Add a "Paint" event handler for "pictureBox_zoom". The Code is as follows:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD48cD48L3A + PHByZSBjbGFzcz0 = "brush: java;"> ///
/// Magnifier component re-painting event handler // display the enlarged image with the mouse pointer in real time ////// /// Private void pictureBox_zoom_Paint (object sender, PaintEventArgs e) {Bitmap BMP _lbl = new Bitmap (e. clipRectangle. width, e. clipRectangle. height); int srcWidth = (int) (this. zoomBoxWidth/10); int srcHeight = (int) (this. zoomBoxHeight/10); Bitmap bmp = new Bitmap (srcWidth, srcHeight); Rectangle srcRect = new Rectangle (MousePosition. x-5, MousePosition. y-4, srcWidth, srcHeight); if (! IsCuting) {srcRect = new Rectangle (MousePosition. x-6, MousePosition. y-5, srcWidth, srcHeight);} Graphics g = Graphics. fromImage (bmp); g. drawImage (screenImage, 0, 0, srcRect, GraphicsUnit. pixel); g. dispose (); // Zoom int x, y; for (int row = 0; row <bmp. height; row ++) {for (int col = 0; col <bmp. width; col ++) {Color pc = bmp. getPixel (col, row); for (int h = 0; h <10; h ++) {for (int w = 0; w <10; w ++) {x = col * 10 + w; y = row * 10 + h; if (x <BMP _lbl.width & y <BMP _lbl.height) {BMP _lbl.setpixel (x, y, pc) ;}}}} e. graphics. drawImage (BMP _lbl, 0, 0); int blockX = e. clipRectangle. width/2; int blockY = e. clipRectangle. height/2; SolidBrush brush = new SolidBrush (Color. fromArgb (10,124,202); Pen pen = new Pen (brush, 2.0F); e. graphics. drawLine (pen, new Point (0, blockY), new Point (e. clipRectangle. width, blockY); e. graphics. drawLine (pen, new Point (blockX, 0), new Point (blockX, e. clipRectangle. height); g. dispose (); BMP _lbl.dispose ();}
Compile, run, and check the effect!
Next article: C # software development instance. Customize your own screen tool (8) Add the keyboard operation function