void formCustomTemplate_MouseDown(object sender, MouseEventArgs e) { var f = (Form)sender; if (e.Button == System.Windows.Forms.MouseButtons.Left) { var p = Cursor.Position; currentScreen = Screen.FromPoint(p).Bounds; originRect = new Rectangle(p.X - 4, p.Y - 4, 8, 8); activeWindow = new WindowBlock() { Location = new Point((p.X - currentScreen.X) / _GridSize.Width * _GridSize.Width + currentScreen.X, (p.Y - currentScreen.Y) / _GridSize.Height * _GridSize.Height + currentScreen.Y), Error = true, Selected = true, MinimumSize = _GridSize, }; var h = activeWindow.Handle; activeWindow.Size = _GridSize; activeWindow.Show(backgrounds[backgrounds.Length - 1]); f.MouseMove += formCustomTemplate_MouseMove; f.MouseCaptureChanged += formCustomTemplate_MouseCaptureChanged; activeWindow.SizeChanged += activeWindow_SizeChanged; } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { NativeMethods.ReleaseCapture(); deleteToolStripMenuItem.Enabled = false; contextMenu.Show(Cursor.Position); } }
/// <summary> /// Initializes windows with absolute positioning /// </summary> public formCustomTemplate(Size minimum, params Rectangle[] windows) : this((formCustomTemplate)null) { this.minimum = new Size(minimum.Width > 0 ? minimum.Width : 200, minimum.Height > 0 ? minimum.Height : 200); if (windows != null) { foreach (var w in windows) { var wb = new WindowBlock() { Bounds = w, MinimumSize = minimum, }; this.windows.Add(wb); } } }
/// <summary> /// Initializes windows with relative positioning /// </summary> public formCustomTemplate(params WindowRects[] windows) : this((formCustomTemplate)null) { foreach (var wr in windows) { var screen = Screen.FromRectangle(wr.Screen).Bounds; foreach (var w in wr.Windows) { var wb = new WindowBlock() { Bounds = Util.ScreenUtil.Constrain(new Rectangle(screen.X + w.X, screen.Y + w.Y, w.Width, w.Height), screen), MinimumSize = minimum, }; this.windows.Add(wb); } } }
void formCustomTemplate_MouseCaptureChanged(object sender, EventArgs e) { var f = (Form)sender; if (activeWindow.Error) { activeWindow.Dispose(); } else { windows.Add(activeWindow); activeWindow.MouseDown += activeWindow_MouseDown; activeWindow.FormClosing += activeWindow_FormClosing; activeWindow.KeyDown += activeWindow_KeyDown; activeWindow = null; } f.MouseMove -= formCustomTemplate_MouseMove; f.MouseCaptureChanged -= formCustomTemplate_MouseCaptureChanged; }