C # Software Development example. Private Custom screenshot Tool (vii) Add Magnifier function

Source: Internet
Author: User

Previous: C # software development examples. Customize your own on-screen tools (vi) Add configuration management features

Because it may be necessary to accurately intercept a certain part, so the function of the magnifying glass, so that when the interception is easier to locate the location.

Add the Picturebox,name property to "Picturebox_zoom";


Add the following code to the "Form1_Load" event handler:

Sets the size of the Magnifier            this.picturebox_zoom. Width = this. Zoomboxwidth;            This.picturebox_zoom. Height = this. Zoomboxheight;
Add code to the "Exitcutimage" method:

Add code to the "Form1_mouseup" event handler function:


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 P                Oint (mouseposition.x + 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 + Mouse Position.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 the "Paint" event handler for "Picturebox_zoom", such as the following code:

        <summary>///Magnifier component Redraw event handlers///real-time display of enlarged image of mouse pointer////</summary>//&L T;param name= "Sender" ></param>//<param name= "E" ></param> private void Picturebox_zoo M_paint (object sender, PaintEventArgs e) {Bitmap bmp_lbl = new Bitmap (E.cliprectangle.width, E.cliprect Angle.            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, SRC            Height);            } 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 < h++) {for (int w = 0; w < w++)                            {x = col * + W;                            y = row * + 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, execute, see the effect!

Next:C # Software development examples. Customize your own on-screen tools (eight) Add keyboard operation function

C # Software Development example. Private custom-made screen tools (vii) Adding Magnifier

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.