/// <summary> /// Constructor for moving or resizing a single control /// </summary> /// <param name="c"></param> /// <param name="state"></param> /// <param name="MouseOrigin"></param> /// <param name="minWidth"></param> /// <param name="minHeight"></param> public DaggerOverlay(Control c, DaggerNodeAlterState state, Point MouseOrigin, int minWidth, int minHeight) { _control = c; editstate = state; Point ulcornerPoint = c.PointToScreen(new Point(0, 0)); origin = new Point(MouseOrigin.X - ulcornerPoint.X, MouseOrigin.Y - ulcornerPoint.Y); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.Blue; this.ForeColor = System.Drawing.Color.LightGreen; this.ControlBox = false; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.ShowInTaskbar = false; this.Name = "EditOverlay"; this.Opacity = 0; //if we are just moving it, copy the region of the control if (state == DaggerNodeAlterState.Move) { Region = c.Region; Bitmap b = new Bitmap(c.Width, c.Height); c.DrawToBitmap(b, c.ClientRectangle); this.BackgroundImage = b; } else { //if we are resizing, make adjustments for mouse origin _minWidth = minWidth; _minHeight = minHeight; Point lrCornerPoint = c.PointToScreen(new Point(c.Width, c.Height)); _resizeOffsetX = lrCornerPoint.X - MouseOrigin.X; _resizeOffsetY = lrCornerPoint.Y - MouseOrigin.Y; } }
/// <summary> /// Constructor for moving multiple controls /// </summary> /// <param name="controls"></param> /// <param name="MouseOrigin"></param> public DaggerOverlay(List <Control> controls, Point MouseOrigin) { _multiControls = controls; editstate = DaggerNodeAlterState.Move; // get the upperleft-most and lowerright-most control positions Point ulcornerPoint = _multiControls[0].PointToScreen(new Point(0, 0)); Point lrcornerPoint = _multiControls[0].PointToScreen(new Point(_multiControls[0].Width, _multiControls[0].Height)); foreach (Control c in _multiControls) { Point tp1 = c.PointToScreen(new Point(0, 0)); Point tp2 = c.PointToScreen(new Point(c.Width, c.Height)); ulcornerPoint = new Point(Math.Min(ulcornerPoint.X, tp1.X), Math.Min(ulcornerPoint.Y, tp1.Y)); lrcornerPoint = new Point(Math.Max(lrcornerPoint.X, tp2.X), Math.Max(lrcornerPoint.Y, tp2.Y)); } // calc the size needed from the previous points _multiControlSize = new Size(lrcornerPoint.X - ulcornerPoint.X, lrcornerPoint.Y - ulcornerPoint.Y); origin = new Point(MouseOrigin.X - ulcornerPoint.X, MouseOrigin.Y - ulcornerPoint.Y); _multiControlCurrentLocation = ulcornerPoint; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.Blue; this.ForeColor = System.Drawing.Color.LightGreen; this.ControlBox = false; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.ShowInTaskbar = false; this.Name = "EditOverlay"; this.Opacity = 0; this.BackgroundImage = new Bitmap(_multiControlSize.Width, _multiControlSize.Height); Graphics g = Graphics.FromImage(this.BackgroundImage); // composite the regions and bitmaps of all the controls into the overlay window foreach (Control c in _multiControls) { Region rr = new Region(c.Region.GetRegionData()); Point screenPoint = c.PointToScreen(new Point(0, 0)); rr.Translate(screenPoint.X - _multiControlCurrentLocation.X, screenPoint.Y - _multiControlCurrentLocation.Y); if (Region != null) { Region.Union(rr); } else { _multiControlRegion = Region = new Region(rr.GetRegionData()); } rr.Dispose(); // copy the controls bitmap onto this one Bitmap b = new Bitmap(c.Width, c.Height); c.DrawToBitmap(b, c.ClientRectangle); g.DrawImage(b, screenPoint.X - _multiControlCurrentLocation.X, screenPoint.Y - _multiControlCurrentLocation.Y); } g.Dispose(); }