2,建立截圖主視窗
核心類MyRectangle已經完成,剩下的工作就是使用改類實現預想的截圖功能。
用VS2005 建立Project,命名為ScreenCutter。將主視窗命名為MainForm,建立一個視窗命名為ScreenBody,將其 ShowInTaskbar屬性設定為False,TopMost屬性設定為True,FormBorderStyle屬性設定為None,在 ScreenBody上添加一個panel控制項panel1,設定BackColor屬性為藍色,在panel1上添加相應個數的label,如 labelLocation、labelWidth、labelHeight等,用於指示當前選區位置和大小,panel1最終樣式為:
修改ScreenBody的引用命名空間為:
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
修改ScreenBody建構函式:
public ScreenBody()
{
InitializeComponent();
panel1.Location = new Point(this.Left, this.Top);
myRectangle = new MyRectangle();
moveModeDownPoint = new Point();
this.Cursor = myRectangle.MyCursor;
}