核心類別 MyRectangle 完成後,接著建立主視窗。使用 VS2005 新建專案 ScreenCutter,主視窗命名 MainForm,新增視窗 ScreenBody 並設定:
ShowInTaskbar = FalseTopMost = TrueFormBorderStyle = None於 ScreenBody 加入 Panel (panel1),背景色設藍色,內含 Label 顯示座標與尺寸(labelLocation、labelWidth、labelHeight)。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ScreenCutter
{
public partial class ScreenBody : Form
{
private Graphics MainPainter;
private bool isDowned;
private bool RectReady;
private Image baseImage;
private Point moveModeDownPoint;
private MyRectangle myRectangle;
private bool moveMode;
private bool changeSizeMode;
public ScreenBody()
{
InitializeComponent();
panel1.Location = new Point(this.Left, this.Top);
myRectangle = new MyRectangle();
moveModeDownPoint = new Point();
this.Cursor = myRectangle.MyCursor;
}
// 後續事件處理見下一篇……
}
}