WPF绘制折线

WPF后台绘制折线,填充到一个GRID下

private void btnPreview_Click(object sender, RoutedEventArgs e)
        {
            GridImg.Children.Clear();
            System.Drawing.Point p0 = new System.Drawing.Point(0, 0);
            System.Drawing.Point p1 = new System.Drawing.Point(0, 0);
            System.Drawing.Point p2 = new System.Drawing.Point(0, 0);
            System.Drawing.Point p3 = new System.Drawing.Point(0, 0);

            int x1 = Convert.ToInt32(txta1.Text);
            int y1 = Convert.ToInt32(txtb1.Text);
            int x2 = Convert.ToInt32(txta2.Text);
            int y2 = Convert.ToInt32(txtb2.Text);

            p0.X = 0; p0.Y = 255;
            p1.X = x1; p1.Y = 255 - y1;
            p2.X = x2; p2.Y = 255 - y2;
            p3.X = 255; p3.Y = 0;

            Line LX = new Line();//X轴
            LX.X1 = 0; LX.X2 = 255; LX.Y1 = 255; LX.Y2 = 255;
            LX.StrokeThickness = 1;
            LX.Stroke = System.Windows.Media.Brushes.Black;
            Line LY = new Line();//Y轴
            LY.X1 = 0; LY.X2 = 0; LY.Y1 = 0; LY.Y2 = 255;
            LY.StrokeThickness = 1;
            LY.Stroke = System.Windows.Media.Brushes.Black;

            Polyline PL = new Polyline();//绘制折线
            PointCollection collection = new PointCollection();
            collection.Add(new System.Windows.Point(p0.X, p0.Y));
            collection.Add(new System.Windows.Point(p1.X, p1.Y));
            collection.Add(new System.Windows.Point(p2.X, p2.Y));
            collection.Add(new System.Windows.Point(p3.X, p3.Y));
            PL.Points = collection;
            PL.Stroke = new SolidColorBrush(Colors.Red);
            PL.StrokeThickness = 1;
            GridImg.Children.Add(LX);
            GridImg.Children.Add(LY);
            GridImg.Children.Add(PL);
        }

 

转载于:https://www.cnblogs.com/ZXdeveloper/p/3781688.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值