首页 > 代码库 > C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码
C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码
C#WPF 如何绘制几何图形? 怎么绘制坐标系?
这离不开Path(System.Windows.Shapes)和StreamGeometry(System.Windows.Media)类。
一、建立WPF工程
二、添加代码
MainWindow.xaml 中代码
<Window x:Class="WPFDrawingTraning.MainWindow" xmlns="<a target=_blank href=http://www.mamicode.com/"http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation">MainWindow.xaml.cs中代码
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace WPFDrawingTraning{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : System.Windows.Window { //Canvas mainPanel = new Canvas(); public MainWindow() { InitializeComponent(); Drawsin();//绘制2D坐标系和sin曲线 Drawpentagon(); } /// <summary> /// 绘制一组线段 /// </summary> protected void Drawing() { PathFigure myPathFigure = new PathFigure(); myPathFigure.StartPoint = new Point(10, 50); LineSegment myLineSegment = new LineSegment(); myLineSegment.Point = new Point(200, 70); PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myLineSegment); myPathFigure.Segments = myPathSegmentCollection; PathFigureCollection myPathFigureCollection = new PathFigureCollection(); myPathFigureCollection.Add(myPathFigure); PathGeometry myPathGeometry = new PathGeometry(); myPathGeometry.Figures = myPathFigureCollection; Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 1; myPath.Data = http://www.mamicode.com/myPathGeometry;>{ point.X += xypoint.X; point.Y = xypoint.Y - point.Y; return point;//显示屏幕坐标系的位置 } }}三、页面效果
C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。