C # screenshot tool winform,

Source: Internet
Author: User

C # tool winform,

After several days, there were a lot of objects and all of them were messy. Finally, I tried them one by one.

Bitmap

Graphics

FromImage

Pen

Rectangle

DrawRectangle

It was really messy. After several days, I understood the relationship between parameters.

Download pan.baidu.com/s/1c2CMRhY

 

Idea: form1 is the interface, full screen. Form2 is just a region

Form1 code

Int I = 0; int w = Screen. primaryScreen. bounds. width; int h = Screen. primaryScreen. bounds. height; private void button#click (object sender, EventArgs e) {WindowState = FormWindowState. minimized; Thread. sleep (100); I + = 1; Bitmap B = new Bitmap (w, h); Graphics g = Graphics. fromImage (B); g. copyFromScreen (0, 0, 0, new Size (w, h); B. save ("C:/Users/Administrator/Desktop/" + I + ". jpg "); WindowState = FormWindowState. normal; Clipboard. setImage (B); this. cursor = Cursors. default;} private void button3_Click (object sender, EventArgs e) {System. diagnostics. process. start ("C:/Users/Administrator/Desktop"); TopMost = false; this. cursor = Cursors. default;} private void button2_Click (object sender, EventArgs e) {this. hide (); Form2 f2 = new Form2 (); f2.Show ();}

 

Form2 code

 

Int I = 0; Bitmap bit; Bitmap bit2; Bitmap copy; int x; int y; int xx; int yy; Pen pen = new Pen (Color. red, 2); Rectangle rect = new Rectangle (); Graphics g2; private void Form2_Load (object sender, EventArgs e) {I +++; // Opacity = 0.5; windowState = FormWindowState. minimized; FormBorderStyle = FormBorderStyle. none; this. cursor = Cursors. cross; int w = Screen. primaryScreen. bounds. width; int h = Screen. primaryScreen. bounds. height; bit = new Bitmap (w, h); // obtain the desktop graph Graphics g = Graphics. fromImage (bit); // picture g. copyFromScreen (0, 0, 0, 0, new Size (w, h); pictureBox1.Image = bit; bit. save ("C:/Users/Administrator/Desktop/region" + I + ". jpg "); WindowState = FormWindowState. maximized;} private void picturebox#mouseclick (object sender, MouseEventArgs e) {if (e. button = MouseButtons. right) {this. hide (); Form1 f1 = new Form1 (); f1.Show () ;}} private void picturebox#mousedown (object sender, MouseEventArgs e) {x = Math. abs (e. x); y = Math. abs (e. y);} private void pictureBox1_MouseMove (object sender, MouseEventArgs e) {if (e. button = MouseButtons. left) {xx = Math. abs (e. x); yy = Math. abs (e. y); Graphics g = pictureBox1.CreateGraphics (); rect = new Rectangle (x, y, xx-x, yy-y); Refresh (); g. drawRectangle (pen, rect) ;}} private void picturebox#mouseup (object sender, MouseEventArgs e) {try {copy = (Bitmap) bit. clone (); bit2 = new Bitmap (rect. width, rect. height); g2 = Graphics. fromImage (bit2); g2.DrawImage (copy, new Rectangle (0, 0, rect. width, rect. height), rect, GraphicsUnit. pixel); pictureBox1.Image = bit2; bit2.Save ("C:/Users/Administrator/Desktop/region" + I + ". jpg "); Clipboard. setImage (bit2 );}

 

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.