コード例 #1
0
        private void DrawTriangle(ITriangle triangle)
        {
            var k = 80.0;

            System.Windows.Point p1 = new System.Windows.Point
            {
                X = k * triangle.GetVertex(0).X + 250.0,
                Y = k * triangle.GetVertex(0).Y + 100.0
            };
            System.Windows.Point p2 = new System.Windows.Point
            {
                X = k * triangle.GetVertex(1).X + 250.0,
                Y = k * triangle.GetVertex(1).Y + 100.0
            };
            System.Windows.Point p3 = new System.Windows.Point
            {
                X = k * triangle.GetVertex(2).X + 250.0,
                Y = k * triangle.GetVertex(2).Y + 100.0
            };
            DrawableTriangle myTriangle = new DrawableTriangle
            {
                Points = new List <System.Windows.Point> {
                    p1, p2, p3
                },
            };

            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 0.2;
            MainCanvas.Children.Add(myTriangle);
        }
コード例 #2
0
        private void DrawCircle(ITriangle triangle)
        {
            Point incenter = GetIncenter(triangle);

            var k = 80.0;

            System.Windows.Point center = new System.Windows.Point
            {
                X = k * incenter.X + 250.0,
                Y = k * incenter.Y + 100.0
            };

            double size = 10;
            //add circle
            Ellipse circle = new Ellipse()
            {
                Width  = size,
                Height = size,
                Stroke = Brushes.Red
            };

            circle.SetValue(Canvas.LeftProperty, center.X - circle.Width / 2);
            circle.SetValue(Canvas.TopProperty, center.Y - circle.Height / 2);
            MainCanvas.Children.Add(circle);
            //add ID
            TextBlock triangleId = new TextBlock();

            triangleId.Text       = triangle.ID.ToString();
            triangleId.Foreground = circle.Stroke;
            Viewbox viewbox = new Viewbox();

            viewbox.Visibility  = Visibility.Visible;
            viewbox.Stretch     = Stretch.Uniform;
            viewbox.Child       = triangleId;
            viewbox.Height      = circle.Height / 2;
            viewbox.Width       = circle.Width / 2;
            viewbox.MouseEnter += ViewBoxOnMouseDown;
            viewbox.SetValue(Canvas.LeftProperty, center.X - viewbox.Width / 2);
            viewbox.SetValue(Canvas.TopProperty, center.Y - viewbox.Height / 2);
            MainCanvas.Children.Add(viewbox);
        }