Exemplo n.º 1
0
        public override void Draw(Canvas canvas)
        {
            var rectangle = new System.Windows.Shapes.Rectangle()
            {
                Height          = Height,
                Width           = Width,
                Stroke          = Color,
                StrokeThickness = Thickness,
                Tag             = Tag
            };

            Tag = rectangle.GetHashCode();
            StartPoint(rectangle, canvas);
            canvas.Children.Add(rectangle);
        }
Exemplo n.º 2
0
        public void DrawRectangle(int _height, int _width, Canvas canvas)
        {
            System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle()
            {
                Width           = _width,
                Height          = _height,
                Stroke          = Brushes.Black,
                StrokeThickness = thickness,
                Fill            = new SolidColorBrush(Colors.Wheat)
            };
            hash = rectangle.GetHashCode(); // каждая нарисованная фигура класса идет через хэшкод
            canvas.Children.Add(rectangle);

            if (firstPoint.X < secondPoint.X && firstPoint.Y <= secondPoint.Y)
            {
                Canvas.SetLeft(rectangle, firstPoint.X);
                Canvas.SetTop(rectangle, firstPoint.Y);
                this.dir = direction.downRight;
            }
            else if (firstPoint.X <= secondPoint.X && firstPoint.Y > secondPoint.Y)
            {
                Canvas.SetLeft(rectangle, firstPoint.X);
                Canvas.SetBottom(rectangle, canvas.ActualHeight - firstPoint.Y);
                this.dir = direction.topRight;
            }
            else if (firstPoint.X > secondPoint.X && firstPoint.Y >= secondPoint.Y)
            {
                Canvas.SetRight(rectangle, canvas.ActualWidth - firstPoint.X);
                Canvas.SetBottom(rectangle, canvas.ActualHeight - firstPoint.Y);
                this.dir = direction.topLeft;
            }
            else if (firstPoint.X >= secondPoint.X && firstPoint.Y < secondPoint.Y)
            {
                Canvas.SetTop(rectangle, firstPoint.Y);
                Canvas.SetRight(rectangle, canvas.ActualWidth - firstPoint.X);
                this.dir = direction.downLeft;
            }
        }