void SetupBackgroundProperties(LayoutFarm.CustomWidgets.AbstractBox backgroundBox) { //if click on background backgroundBox.MouseDown += (s, e) => { //remove all controller box RemoveAllControllerBoxes(); }; //when start drag on bg //just show selection box on top most backgroundBox.MouseDrag += (s, e) => { //move to mouse position if (!selectionBoxIsShown) { selectionBox.LandingPoint = new Point(e.X, e.Y); selectionBox.SetLocation(e.X, e.Y); selectionBox.Visible = true; selectionBoxIsShown = true; e.SetMouseCapture(selectionBox); } else { Point pos = selectionBox.LandingPoint; int x = pos.X; int y = pos.Y; int w = e.X - pos.X; int h = e.Y - pos.Y; if (w < 0) { w = -w; x -= w; } if (h < 0) { h = -h; y -= h; } //set width and height selectionBox.SetLocationAndSize(x, y, w, h); e.SetMouseCapture(selectionBox); } e.StopPropagation(); }; backgroundBox.MouseUp += (s, e) => { if (selectionBoxIsShown) { FindSelectedUserBoxes(); selectionBox.Visible = false; selectionBox.SetSize(1, 1); selectionBoxIsShown = false; } e.StopPropagation(); }; }
void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.AbstractBox box) { //1. mouse down box.MouseDown += (s, e) => { //box.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); e.MouseCursorStyle = MouseCursorStyle.Pointer; //-------------------------------------------- //request user controller for this box if (this.BoxSelectionMode == DzBoardSample.BoxSelectionMode.Single) { RemoveAllControllerBoxes(); } var userControllerBox = GetFreeControllerBox(); userControllerBox.TargetBox = box; //-------- //get position relative to box var loca1 = box.GetGlobalLocation(); userControllerBox.SetLocation(loca1.X - 5, loca1.Y - 5); userControllerBox.SetSize(box.Width + 10, box.Height + 10); userControllerBox.Visible = true; userControllerBox.Focus(); e.SetMouseCapture(userControllerBox); e.StopPropagation(); //-------------------------------------------- }; //2. mouse up box.MouseUp += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Default; //box.BackColor = Color.LightGray; RemoveAllControllerBoxes(); e.StopPropagation(); }; }