protected override void OnStartDemo(SampleViewport viewport) { this.viewport = viewport; this.rootgfx = viewport.ViewportControl.RootGfx; //-------------------------------- bgbox = new LayoutFarm.CustomWidgets.SimpleBox(800, 600); bgbox.BackColor = Color.White; bgbox.SetLocation(0, 0); SetupBackgroundProperties(bgbox); viewport.AddContent(bgbox); //user box1 var box1 = new LayoutFarm.CustomWidgets.SimpleBox(150, 150); box1.BackColor = Color.Red; box1.SetLocation(10, 10); SetupActiveBoxProperties(box1); bgbox.AddChild(box1); var box2 = new LayoutFarm.CustomWidgets.SimpleBox(60, 60); box2.BackColor = Color.Yellow; box2.SetLocation(50, 50); SetupActiveBoxProperties(box2); bgbox.AddChild(box2); var box3 = new LayoutFarm.CustomWidgets.SimpleBox(60, 60); box3.BackColor = Color.OrangeRed; box3.SetLocation(200, 80); SetupActiveBoxProperties(box3); bgbox.AddChild(box3); selectionBox = new UISelectionBox(1, 1); selectionBox.Visible = false; selectionBox.BackColor = Color.FromArgb(80, Color.Green); viewport.AddContent(selectionBox); SetupSelectionBoxProperties(selectionBox); }
void SetupSelectionBoxProperties(UISelectionBox selectionBox) { selectionBox.MouseUp += (s, e) => { if (selectionBoxIsShown) { FindSelectedUserBoxes(); selectionBox.Visible = false; selectionBox.SetSize(1, 1); selectionBoxIsShown = false; } }; selectionBox.MouseDrag += (s, e) => { if (selectionBoxIsShown) { Point sel_globalLocation = selectionBox.GetGlobalLocation(); int x = e.CapturedMouseX; int y = e.CapturedMouseY; //temp fix here //TODO: get global position of selected box int w = selectionBox.Left + e.DiffCapturedX; int h = selectionBox.Top + e.DiffCapturedY; if (w < 0) { w = -w; x -= w; } if (h < 0) { h = -h; y -= h; } //set width and height selectionBox.SetBounds(x, y, w, h); e.StopPropagation(); } }; }