zoukankan      html  css  js  c++  java
  • Silverlight开发历程—(用C#来绘制图形)

     在Silverlight中利用C#来绘制图形比较简单,经常用的两种方法是直接创建对象然后添加到页面容器中和创建XAML创建对象然后利用XamlReader.Load方法加载到容器中。

    比较简单,直接上代码:

    第一种:

    public void DrawPolyLine()
            {
                //创建Polyline
                Polyline polyline = new Polyline();
                //创建坐标集合
                PointCollection points = new PointCollection();
                points.Add(new Point(50,300));
                points.Add(new Point(50,50));
                points.Add(new Point(200,300));
                polyline.Points = points;
                //填充背景色与线条颜色
                polyline.Fill = new SolidColorBrush(Colors.Orange);
                polyline.Stroke = new SolidColorBrush(Colors.Black);
                polyline.StrokeThickness = 3;
    
                //设置位置
                Canvas.SetTop(polyline, 50);
                Canvas.SetLeft(polyline, 50);
                //向容器添加控件
                LayoutRoot.Children.Add(polyline);
            }
            public void DrawPolygon()
            {
                //创建Polygon
                Polygon polygon = new Polygon();
                //创建坐标集合
                PointCollection points = new PointCollection();
                points.Add(new Point(50, 300));
                points.Add(new Point(50, 50));
                points.Add(new Point(200, 300));
                polygon.Points = points;
                //填充背景色与线条颜色
                polygon.Fill = new SolidColorBrush(Colors.Orange);
                polygon.Stroke = new SolidColorBrush(Colors.Black);
                polygon.StrokeThickness = 3;
    
                //设置位置
                Canvas.SetTop(polygon, 50);
                Canvas.SetLeft(polygon, 300);
                //向容器添加控件
                LayoutRoot.Children.Add(polygon);
            }


    运行结果:

    第二种:

     public void DrawPathWithXML()
            {
                string xaml = "<Path ";
                //引用
                xaml+=" xmlns=\"http://schemas.microsoft.com/client/2007\"";
                //创建属性
                xaml += " Stroke=\"Blue\" StrokeThickness=\"3\" ";
                xaml += string.Format(" Data=\"{0}\" />", "M 10,100 Q100,200 300,100");
                //创建路径对象
                Path path = new Path();
    
                path = (Path)XamlReader.Load(xaml);
    
                LayoutRoot.Children.Add(path);
            }


    运行结果:

    下一节将综合前台学到的绘图方式来绘制一个报表折线统计图。

  • 相关阅读:
    Oracle startup startup nomount startup mount 的区别
    Linux 查看磁盘是否为SSD
    Spark入门实战系列--4.Spark运行架构
    Hbase 的java 增删改查操作
    Hbase 的一些重要网站链接,有空没空的搂两眼
    一段生成大数据测试数据的java code 片段
    一段简单的java 代码,用于日期格式转化
    一个简单的jsp 页面
    Scala 版 word count
    db2expln 查看执行plan
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114896.html
Copyright © 2011-2022 走看看