Example #1
0
        private void CanvasPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (IsMultiSelecting)
            {
                var geometry       = new RectangleGeometry(new Rect(SelectionSquareTopLeft, e.GetPosition(CanvasPanel)));
                var visualInRegion = CanvasPanel.GetVisuals(geometry);

                MessageBox.Show($"选中数量:{visualInRegion.Count}");
                IsMultiSelecting = false;
                CanvasPanel.RemoveVisual(SelectionSquare);
                CanvasPanel.ReleaseMouseCapture();
            }
            else
            {
                IsDragging = false;
            }
        }
Example #2
0
        private void VisualCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var pointClicked = e.GetPosition(CanvasPanel);

            if (rbAdd.IsChecked == true)
            {
                var visual = new DrawingVisual();
                DrawSquare(visual, pointClicked, false);
                CanvasPanel.AddVisual(visual);
            }
            else if (rbDelete.IsChecked == true)
            {
                var visual = GetVisual(pointClicked);
                if (visual != null)
                {
                    CanvasPanel.RemoveVisual(visual);
                }
            }
            else if (rbSelected.IsChecked == true)
            {
                var visual = GetVisual(pointClicked);
                if (visual != null)
                {
                    var topLeftCorner = new Point(visual.ContentBounds.TopLeft.X + DrawingPen.Thickness / 2,
                                                  visual.ContentBounds.TopLeft.Y + DrawingPen.Thickness / 2);
                    DrawSquare(visual, topLeftCorner, true); // 重绘为黄色
                    ClickOffet = topLeftCorner - pointClicked;
                    IsDragging = true;
                    if (SelectedVisual != null && SelectedVisual != visual)
                    {
                        ClearSelection(); // 将原来为黄色的重绘为淡蓝
                    }
                    SelectedVisual = visual;
                }
            }
            else if (rbSelectMultiple.IsChecked == true)
            {
                SelectionSquare = new DrawingVisual();
                CanvasPanel.AddVisual(SelectionSquare);
                SelectionSquareTopLeft = pointClicked;
                IsMultiSelecting       = true;
                CanvasPanel.CaptureMouse();
            }
        }