Implementation of the winform screenshot Program

Source: Internet
Author: User

ProgramOfCodeI have referenced an Indian blog and Zhou yinhui's blog. Both of them are made of WPF. The translucent masks are all made of the canvas in WPF, but winform does not have this control, I came up with another method.

The general idea is to press the button to open another form. This form has no border. In the initial stage, it is to maximize the entire screen. The background color is white and the transparency is 50%. in this way, it is almost a translucent mask effect, and the attribute of displaying icons on the taskbar also needsSet it to false so that everyone can understand what I mean. when capturing some images on the screen, the translucent color of this part should be restored to the true face of the screen, so I thought of a way to set the transparencykey of this window to cornflowerblue, then draw the rectangle frame of the cornflowerblue color on the screen, so that the color of the frame area can be changed to the screen color. the effect is as follows:

 

The rectangle is drawn like this:

Private void form2_mousedown (Object sender, mouseeventargs e) {x = mouseposition. x; y = mouseposition. y; ismouthdown = true;} private void form2_mousemove (Object sender, mouseeventargs e) {If (ismouthdown) {width = math. ABS (mouseposition. x-x); Height = math. ABS (mouseposition. y-y); G = creategraphics (); G. clear (backcolor); G. fillrectangle (brushes. cornflowerblue, x <mouseposition. x? X: mouseposition. X, Y <mouseposition. Y? Y: mouseposition. y, width + 1, height + 1) ;}} private void form2_mouseup (Object sender, mouseeventargs e) {nowx = mouseposition. X + 1; Nowy = mouseposition. Y + 1; this. close (); formmain. pcurrentwin. snap (x <nowx? X: nowx, Y <Nowy? Y: Nowy, math. Abs (nowx-x), math. Abs (Nowy-y); // start formmain. pcurrentwin. Show ();}

As mentioned in Zhou's blog, this drawing method works well on a single monitor, and there is a significant lag in the dual monitor... I don't have a dual-display environment. I hope someone can help me to test whether there is any lag in this frame in the dual-display. but in fact, when running on my computer, when the mouse moves and re-draws this rectangle, although there is no sense of lag, it is still CPU-consuming. I don't know how to draw a translucent blue rectangle on the Windows 7 desktop?

In addition, I found that copyfromscreen written by these two people seems to have a problem, such as weekly:

 
G. copyfromscreen (RC. X, RC. Y, 0, 0, RC. Size, copypixeloperation. sourcecopy );

I uploaded these parameters later, but I found that when I captured the full screen, for example, my monitor was 1280*800, but it was always as big as 1279*799, if you click (0, 0) in the upper left corner of the screen, the entire screen is captured! So I added 1 to the length and width of this rectangle, so it is normal... but it is not clear why (especially when you click the upper left corner to access the entire screen ).

Program Interface (some functions are not yet written ):

Program download: screensnap.zip

download code: screensnapcode.zip

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.