コード例 #1
0
        private void drawCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            //Check which shape to draw, and then draw
            if (DrawObject == Btn1Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                p2 = e.GetPosition(drawCanvas);

                double minX = Math.Min(p2.X, p1.X);
                double minY = Math.Min(p2.Y, p1.Y);
                double maxX = Math.Max(p2.X, p1.X);
                double maxY = Math.Max(p2.Y, p1.Y);

                double height = Math.Abs(maxY - minY);
                double width  = Math.Abs(maxX - minX);

                ellipse.Height = height;
                ellipse.Width  = width;

                double left   = p1.X - (width / 2);
                double top    = p1.Y - (height / 2);
                double right  = -1 * (p1.X - (width / 2));
                double bottom = -1 * (p1.Y - (height / 2));

                ellipse.Margin = new Thickness(left, top, right, bottom);
            }
            else if (DrawObject == Btn2Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                p2 = e.GetPosition(drawCanvas);

                double minX = Math.Min(p2.X, p1.X);
                double minY = Math.Min(p2.Y, p1.Y);
                double maxX = Math.Max(p2.X, p1.X);
                double maxY = Math.Max(p2.Y, p1.Y);

                double height = Math.Abs(maxY - minY);
                double width  = Math.Abs(maxX - minX);

                rectangle.Height = height;
                rectangle.Width  = width;

                double left   = p1.X - (width / 2);
                double top    = p1.Y - (height / 2);
                double right  = -1 * (p1.X - (width / 2));
                double bottom = -1 * (p1.Y - (height / 2));

                rectangle.Margin = new Thickness(left, top, right, bottom);
            }
            else if (DrawObject == Btn3Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                line.X1 = p1.X;
                line.Y1 = p1.Y;
                line.X2 = e.GetPosition(drawCanvas).X;
                line.Y2 = e.GetPosition(drawCanvas).Y;
            }
            else if (DrawObject == Btn4Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                p2 = e.GetPosition(drawCanvas);
                polyline.Points.Add(p2);
            }
        }
コード例 #2
0
 //Button Control
 private void Btn1_Click(object sender, RoutedEventArgs e)
 {
     DrawObject     = Btn1Text.ToLower().ToString();
     btn1.IsEnabled = false;
     btn2.IsEnabled = true;
     btn3.IsEnabled = true;
     btn4.IsEnabled = true;
 }
コード例 #3
0
        private void drawCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            p1 = e.GetPosition(drawCanvas);

            //Checks which shape to draw, creates and sets the shapes values, and adds the to the canvas
            if (DrawObject == Btn1Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                ellipse = new Ellipse
                {
                    Fill            = FillColor,
                    Stroke          = StrokeColor,
                    StrokeThickness = 2
                };
                drawCanvas.Children.Add(ellipse);
            }
            else if (DrawObject == Btn2Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                rectangle = new Rectangle()
                {
                    Fill            = FillColor,
                    Stroke          = StrokeColor,
                    StrokeThickness = 2
                };
                drawCanvas.Children.Add(rectangle);
            }
            else if (DrawObject == Btn3Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                line = new Line()
                {
                    Stroke          = StrokeColor,
                    StrokeThickness = 2
                };
                drawCanvas.Children.Add(line);
            }
            else if (DrawObject == Btn4Text.ToLower().ToString() && e.LeftButton == MouseButtonState.Pressed)
            {
                polyline = new Polyline()
                {
                    Stroke          = StrokeColor,
                    StrokeThickness = 2
                };
                drawCanvas.Children.Add(polyline);
            }
        }