Silverlight开发历程—(用C#来绘制图形)

Silverlight开发历程—(用C#来绘制图形),第1张

概述 在Silverlight中利用C#来绘制图形比较简单,经常用的两种方法是直接创建对象然后添加到页面容器中和创建XAML创建对象然后利用XamlReader.Load方法加载到容器中。 比较简单,直接上代码: 第一种: public void DrawPolyLine() { //创建Polyline Polyline poly

 在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));            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);        }


运行结果:

 

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

总结

以上是内存溢出为你收集整理的Silverlight开发历程—(用C#来绘制图形)全部内容,希望文章能够帮你解决Silverlight开发历程—(用C#来绘制图形)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1072232.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存