void MyRectangleDc(Point pt1, Point pt2) { Apis.MoveToEx(hdc, pt1.X, pt1.Y, IntPtr.Zero); //Apis.LineTo(hdc, pt2.X, pt2.Y); int left, top, right, bottom; left = pt1.X; top = pt1.Y; right = pt2.X; bottom = pt2.Y; Apis.Rectangle(hdc, left, top, right, bottom); }
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { base.OnMouseDown(e); if (!isStart) { isStart = true; current = new Point(e.X, e.Y); temp = new Point(e.X, e.Y); hdc = Apis.GetDC(this.Handle); Apis.SetROP2(hdc, R2.R2_NOTXORPEN); } else { MyRectangle(current, temp); MyRectangle(current, new Point(e.X, e.Y)); Apis.ReleaseDC(this.Handle, hdc); } }