The front array changed the code of the section C # screenshot, and it is now useful to use it for everyone.
Primary file
CaptureScreenform.cs
Using system.drawing; using system.collections; using system.windows.form; using system.data; using system.runtime.interopservices;
Namespace CaptureScreen {///
Public static image image = null; private system.windows.Forms.Panel Panel1;
///
Public CapturescreenForm () {// // Windows Form Designer Support for // InitializationComponent ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#REGION Windows Form Designer The code ///
/// summary> private void InitializeComponent () {this.picbox = new System.Windows.Forms.PictureBox (); this.fullScreenBtn = new System.Windows.Forms.Button (); this.mouseCaptureBtn = new System. Windows.Forms.Button (); this.clearbtn = new system.windows.Forms.Button (); this.savebtn = new system.windows.Forms.Button (); this.aboutbtn = new system.windows.Forms.Button (); This.exitbtn = new system.windows.Forms.Button (); this.Panel1 = new system.windows.Forms.Panel (); this.panel1.suspendlayout (); this.suspendlayout (); // / / picbox // this.picbox.location = new system.drawing.point (0, 40); this.picbox.name = "picbox"; this.picbox.size = new system.drawing.size (680, 312); this.picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.picbox.TabIndex = 0; this.picbox.TabStop = false; // // fullScreenBtn // this.fullScreenBtn.Location = new System.Drawing. Point (0, 0); this.fullscreenbtn.name = "fullscreenbtn"; this.ffullscre enBtn.Size = new System.Drawing.Size (96, 32); this.fullScreenBtn.TabIndex = 1; this.fullScreenBtn.Text = "Full Screen taken"; this.fullScreenBtn.Click = new System.EventHandler (this.fullScreenBtn_Click ); // // mouseCaptureBtn // this.mouseCaptureBtn.Location = new System.Drawing.Point (120, 0); this.mouseCaptureBtn.Name = "mouseCaptureBtn"; this.mouseCaptureBtn.Size = new System.Drawing.Size ( 96, 32); this.mousecapturebtn.tabindex = 2; this.mousecapturebtn.text = "Interval"; this.mousecapturebtn.click = new system.eventhandler (this.mousecapturebtn_click);
// // clearbtn // this.clearbtn.location = new system.drawing.point (240, 0); this.clearbtn.name = "clearbtn"; this.clearbtn.size = new system.drawing.size (88, 32); this.clearbtn.tabindex = 3; this.clearbtn.text = "Clear intercept picture"; this.clearbtn.click = new system.eventhandler (this.clearbtn_click; /// savebtn // this.savebtn .Location = new system.drawing.point (352, 0); this.savebtn.name = "savebtn"; this.savebtn.size = new system.drawing.size (96, 32); this.savebtn.tabindex = 4 ; this.saveBtn.Text = "save interception picture"; this.saveBtn.Click = new System.EventHandler (this.saveBtn_Click); // // aboutBtn // this.aboutBtn.Location = new System.Drawing.Point ( 472, 0); this.aboutbtn.name = "aboutbtn"; this.aboutbtn.size = new system.drawing.size (96, 32); this.aboutbtn.tabindex = 5; this.aboutbtn.text = " "; This.aboutbtn.click = new system.eventhandler (this.aboutbtn_click); // // EXITBTN // this.exitbtn.location = new system.drawing.point (5 92, 0); this.exitbtn.Name = "exitbtn"; this.exitbtn.size = new system.drawing.size (88, 32); this.exitbtn.tabindex = 6; this.exitbtn.text = " "; This.exitbtn.click = new system.eventhandler (this.exitbtn_click); /// Panel1 // this.Panel1.controls.add (this.Mousescreenbtn); this.Panel1.controls.add (this.mousecapturebtn This.Panel1.controls.add (this.clearbtn); this.panel1.controls.add (this.savebtn); this.panel1.controls.add (this.aboutbtn); this.Panel1.controls.add (this .exitbtn; this.panel1.location =
New system.drawing.point (0, 0); this.Panel1.name = "panel1"; this.Panel1.size = new system.drawing.size (680, 32); this.Panel1.tabindex = 7; //// // CaptureScreenForm // this.autoscalebasesize = new system.drawing.size (6, 14); this.Autoscroll = true; this.clientsize = new system.drawing.size (696, 358); this.controls.add (this .panel1); this.Controls.add (this.picbox); this.name = "captureScreenform"; this.text = "intercept screen"; this.Panel1.ResumeLayout (false); this.ResumeLayout (false);} # EndRegion
///
Protected Override Void Onpaint (PainTeventargs E) {base.onpaint (e); if (image! = null) {this.picbox.image = image;} else {this.picbox.Image = null; this.picbox.refresh () }}
/ / Quote API
[System.Runtime.InteropServices.dllimportattribute ("gdi32.dll")] public static extern BOOL Bitblt (INTPTR HDCDEST, / / Target device handle int NXDEST, // target INT NYDEST, // Target The X coordinate int NWIDTH, / / target object's rectangular width int nHEight, // Target object's rectangular length INTPTR HDCSRC, // Source The handle INT NXSRC, // Source object's left upper left corner Coordinate int NYSRC, // The X coordinate system.int32 dwrop // raster is operated;
Private void exitbtn_click (object sender, system.eventargs e) {Application.exit ();
Private Void Aboutbtn_Click (Object Sender, System.EventArgs E) {MessageBox.show ("Code by Star IN 2006-3-17, E_MAIL: YGH_01@163.com, thank you to use this.");}
Private Void Clearbtn_Click (Object Sender, System.EventArgs E) {CaptureScreenform.Image = null; this.invalidate ();
private void saveBtn_Click (object sender, System.EventArgs e) {bool isSave = true; SaveFileDialog saveImageDialog = new SaveFileDialog (); saveImageDialog.Title = "Capture screen image save dialog"; saveImageDialog.Filter = @ "jpeg | * .jpg | BMP | * .BMP | GIF | * .GIF "; if (SaveImageDialog.Showdialog () == DialogResult.ok) {string filename = SaveImageDialog.FileName.toString (); if (filename! =" && filename! = null ) {String fileextName = filename.substring (filename.lastindexof (".") 1) .tostring ();
(! FileExtName = ""); System.Drawing.Imaging.ImageFormat imgformat = null if {switch (fileExtName) {case "jpg": imgformat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "bmp": imgformat = System.drawing.Imaging.ImageFormat.Bmp; Break; Case "gif": imgformat = system.drawing.image.imageformat.gif; break; default: messagebox.show ("only access to: JPG, BMP, GIF Format "); issave = false; Break;}
}
// Default Save JPG format if (imgformat == null) {imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;} if (isSave) {try {CaptureScreenForm.image.Save (fileName, imgformat); MessageBox.Show ( "The picture has been successfully saved! ~~");} catch {messagebox.show ("Save failed, you have not intercepted the picture or empty the picture!");}}
}
}
private void fullScreenBtn_Click (object sender, System.EventArgs e) {CaptureScreenForm.image = windowFullScreen (); picbox.Image = CaptureScreenForm.image;} public static Bitmap windowFullScreen () {// build screen Graphics Graphics grpScreen = Graphics.FromHwnd (IntPtr .Zero); // build according to the screen size of the bitmap bitmap bitmap = new bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, grpScreen); // build bitmap related Graphics Graphics grpBitmap = Graphics.FromImage (Bitmap); // Establish screen context INTPTR HDCSCREEN = Grpscreen.getHDC (); // Setting up bitmap context INTPTR HDCBITMAP = GrPbitMap.GETHDC (); // Save the screen in the map Bitblt (HDCBitmap, 0, 0 Bitmap.width, bitmap.height, hdcscreen, 0,0,0x00cc0020); // Close bitmap handle GrPbitMap.ReleaseHDC (HDCBITMAP); // Close screen handle Grpscreen.ReleaseHDC (hdcscreen); // Release bitmap object Grpbitmap.dispose (); // Release screen object Grpscreen.dispose ();
// Return to the capture bitmap return bitmap;}
Private void mousecapturebtn_click (object sender, system.eventargs e) {mousecaptureform mousecapture = new mousecaptureform (); mousecapture.show ();}}}
Another screenshot file:
Mousecaptureform.cs
Using system; using system.collections; using system.componentmodel; using system.windows.form;
Namespace CaptureScreen {///
// /////initiRizeComponent () support for Windows Form Designer Support;
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#REGION Windows Form Designer The code ///
#ndregion
///
Protected Override Void onPaint (Painteventargs E) {base.onpaint (e); E.Graphics.drawRectangle (New Pen (this.Forecolor), this.area); for (int i = 1; i <9; i ) {e .Graphics.FillRectangle (New Solidbrush (Color.green), this.getHandleRect (i));}}
Private Rectangle GetHandleRect (int index) {Point Point = getHandle (index); Return New Rectangle (Point.x - 3, Point.y - 3, 6, 6);
Private point getHandle (int index) {Int x, y, xceenter, ycenter
Xcenter = area.x area.width / 2; ycenter = area.y area.Height / 2; x = area.x; y = area.y;
Switch (index) {casse 1: x = area.x; y = area.y; break; casse 2: x = xcenter; y = area.y; break; casse 3: x = area.right; y = area. Y; Break; Case 4: x = area.right; y = ycenter; break; casse 5: x = area.right; y = area.bottom; break; cas 6: x = xcenter; y = area.bottom; break Case 7: x = area.x; y = area.bottom; break; casser 8: x = area.x; y = ycenter; Break;} return new point (x, y);
Protected Override Void OnMouseUp (MouseEventArgs E) {Base.OnmouseUp (e); int = area.tic; int = area.top; int = area.right; int bottom = area.bottom; area.x = math. MIN (Left, Right); Area.y = Math.min (Top, Bottom); Area.Width = Math.Abs (Left-Right); Area.Height = Math.Abs (Top-Bottom); this.tiptext. TEXT = SELECTEDSTRING; if (e.Button == mousebuttons.right) {if (this.area == Rectangle.empty) {this.close ();} else {this.area = Rectangle.empty; this.invalidate () ;}} This.index = this.getSelectedHandle (New Point (EX, EY)); this.SetCursor ();}
Private int getSelectedHandle (POINT P) {int index = -1; for (int i = 1; i <9; i ) {if (GetHandleRect (i) .contains (p)) {index = i; break;}} (this.area.contains (p)) index = 0;
Return index;}
Protected Override Void OnMouseMove (MouseEventArgs E) {Base.Onmousemove (E); if (this.cape) {this.moveHandleto (New Point (EX, EY)); this.invalidate ();} else {this.index = THIS .GetSelectedHandle (New Point (EX, EY)); this.SetCursor ();}} private void movehandleto (point point) {int = area.LEFT; int top = area.top; int right = area.right; int right = area.right; int Bottom = Area.bottom;
Switch (index) {cas 0: area.x = point.x - this.pot.x; area.y = point.y - pot.y; this.pot = POINT; RETURN; case 1: left = Point .X; Top = Point.y; Break; Case 2: Top = Point.y; Break; Case 3: Right = Point.x; Top = Point.y; Break; Case 4: Right = Point.x; Break; Case 5: Right = Point.x; bottom = point.y; break; cas 6: bottom = point.y; break; case 7: left = point.x; bottom = point.y; break; cas 8: left = Point.x; Break;} this.pot = point; area.x = left; area.wi = top; area.width = right - left; area.height = bottom - top;}
private void MouseCaptureForm_DoubleClick (object sender, System.EventArgs e) {// corrected image taken through the boundary prompt memory BUG int left = area.Left; int right = area.Right; int top = area.Top; int bottom = area. Bottom; if (left
private void MouseCaptureForm_KeyDown (object sender, System.Windows.Forms.KeyEventArgs e) {if (e.KeyData == Keys.Escape && System.Windows.Forms.Button.MouseButtons == MouseButtons.Left) {this.area = Rectangle. Empty; this.invalidate (); tiptext.text = nosectString;} else if (e.keydata == keys.escape) {this.close ();}}
private void tiptext_MouseMove (object sender, System.Windows.Forms.MouseEventArgs e) {if (tiptext.Location.X == 10 && tiptext.Location.Y == 10) {Point formloc = new Point ((Screen.PrimaryScreen.Bounds .Width - 176), 10); tiptext.location = formloc;} else {tiptext.location = new point (10, 10);}}