2, create a screenshot of the main window
Core class MyRectangle has been completed, the rest of the work is to use the modified class to achieve the desired screenshot function.
Use VS2005 to create a new project named Screencutter. Name the main window mainform, create a new window named Screenbody, set its ShowInTaskbar property to False,topmost property set to None for the True,formborderstyle property, Add a Panel control Panel1 on the Screenbody, set the BackColor property to blue, add the corresponding number of labels to panel1, such as Labellocation, Labelwidth, Labelheight, and so on. Used to indicate the current selection position and size, the PANEL1 final style is:
The reference namespace for modifying Screenbody is:
using System;
using System.Drawing;
using System.Windows.Forms;
在ScreenBody类中添加如下私有成员:
private Graphics MainPainter; //the main painter
private bool isDowned; //check whether the mouse is down
private bool RectReady; //check whether the rectangle is finished
private Image baseImage; //the back ground of the screen
private Point moveModeDownPoint; //the mouse location when you move the rectangle
private MyRectangle myRectangle; //the rectangle
private bool moveMode; //check whether the rectangle is on move mode or not
private bool changeSizeMode; //check whether the rectangle is on change size mode or not
To modify the Screenbody constructor:
public ScreenBody()
{
InitializeComponent();
panel1.Location = new Point(this.Left, this.Top);
myRectangle = new MyRectangle();
moveModeDownPoint = new Point();
this.Cursor = myRectangle.MyCursor;
}