Exemple #1
0
        private void renderPanel_MouseDown(object sender, MouseEventArgs e)
        {
            _pickStart = _lastLocation = e.Location;

            bool accumulate = ModifierKeys.HasFlag(Keys.Control);

            // Switch to control dragging instead of selection if the mouse is pressed while above a control
            if (DialogModel != null && DialogModel.EffectiveScale == 1)
            {
                // Loop through all controls from back to front
                for (int i = DialogModel.Controls.Count - 1; i >= 0; i--)
                {
                    if (DialogModel.Controls[i].DrawBox.Contains(_pickStart))
                    {
                        _dragControl = DialogModel.Controls[i];

                        // Remove all previous selections unless the user wants to accumulate selections
                        if (!accumulate)
                        {
                            listBox.ClearSelected();
                        }

                        // Toggle entries when accumulating
                        if (accumulate && listBox.SelectedItems.Contains(_dragControl))
                        {
                            listBox.SelectedItems.Remove(_dragControl);
                        }
                        else
                        {
                            listBox.SelectedItems.Add(_dragControl);
                        }

                        // Only select top-most control
                        return;
                    }
                }
            }
        }
Exemple #2
0
        private void renderPanel_MouseUp(object sender, MouseEventArgs e)
        {
            if (renderPanel.Engine == null)
            {
                return;
            }

            if (_dragControl == null)
            {
                // Select all controls within the rectangle
                var selectedControls = DialogModel.PickControls(Rectangle.FromLTRB(
                                                                    _pickStart.X <e.X?_pickStart.X : e.X,
                                                                                  _pickStart.Y <e.Y?_pickStart.Y : e.Y,
                                                                                                _pickStart.X> e.X?_pickStart.X : e.X,
                                                                                  _pickStart.Y> e.Y ? _pickStart.Y : e.Y));

                bool accumulate = ModifierKeys.HasFlag(Keys.Control);

                // Remove all previous selections unless the user wants to accumulate selections
                if (!accumulate)
                {
                    listBox.ClearSelected();
                }

                // Transfer selection to the list box
                if (selectedControls.Count == 0)
                {
                    // Select dialog if no controls were selected
                    listBox.SelectedIndex = 0;
                }
                else
                {
                    foreach (var control in selectedControls)
                    {
                        // Don't select GroupBoxes in multi-selections
                        if (!(selectedControls.Count > 1 && control is GroupBox))
                        {
                            // Toggle entries when accumulating
                            if (accumulate && listBox.SelectedItems.Contains(control))
                            {
                                listBox.SelectedItems.Remove(control);
                            }
                            else
                            {
                                listBox.SelectedItems.Add(control);
                            }
                        }
                    }
                }

                _pickRectangle = Rectangle.Empty;
            }
            else
            {
                // Check if the control was actually moved away from its initial position
                if (_pickStart != e.Location)
                {
                    OnChange();
                }

                _dragControl = null;
            }

            renderPanel.Engine.Render();
        }