
WPF后台绘制折线,填充到一个GRID下
private void btnPreview_Click(object sender, RoutedEventArgs e)
{
GridImg.Children.Clear();
System.Drawing.Point p0 = new System.Drawing.Point(, );
System.Drawing.Point p1 = new System.Drawing.Point(, );
System.Drawing.Point p2 = new System.Drawing.Point(, );
System.Drawing.Point p3 = new System.Drawing.Point(, ); 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 = ; p0.Y = ;
p1.X = x1; p1.Y = - y1;
p2.X = x2; p2.Y = - y2;
p3.X = ; p3.Y = ; Line LX = new Line();//X轴
LX.X1 = ; LX.X2 = ; LX.Y1 = ; LX.Y2 = ;
LX.StrokeThickness = ;
LX.Stroke = System.Windows.Media.Brushes.Black;
Line LY = new Line();//Y轴
LY.X1 = ; LY.X2 = ; LY.Y1 = ; LY.Y2 = ;
LY.StrokeThickness = ;
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 = ;
GridImg.Children.Add(LX);
GridImg.Children.Add(LY);
GridImg.Children.Add(PL);
}