我们先看看效果如何:

xaml文件:

<Window x:Class="WPF2D绘制图形方法.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="" Background="DarkSalmon">
<Grid Name="Grid1" Height="" Width="">
<Button Content="一般方式绘制" Height="" HorizontalAlignment="Right" Margin="0,12,329,0" Name="button1" VerticalAlignment="Top" Width="" />
<Button Content="高性能绘制" Height="" HorizontalAlignment="Left" Margin="141,11,0,0" Name="button2" VerticalAlignment="Top" Width="" />
<Button Content="图形运算" Height="" HorizontalAlignment="Left" Margin="279,9,0,0" Name="button3" VerticalAlignment="Top" Width="" />
<Label Content="WPF2D绘制图形展示" Height="" HorizontalAlignment="Left" Margin="99,41,0,0" Name="label1" VerticalAlignment="Top" FontSize="" Width="" />
</Grid>
</Window>

我们具体看看代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 WPF2D绘制图形方法
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.button1.Click += new RoutedEventHandler(button1_Click);
this.button2.Click += new RoutedEventHandler(button2_Click);
this.button3.Click += new RoutedEventHandler(button3_Click);
} void button1_Click(object sender, RoutedEventArgs e)
{
//绘制一个简单的矩形,System.Windows.Shapes 基类
//http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.shapes(v=vs.100).aspx
Rectangle MyRectangle = new Rectangle();
MyRectangle.Margin = new Thickness(, , , );
MyRectangle.Width = ;
MyRectangle.Height = ;
MyRectangle.Fill = Brushes.BlanchedAlmond;
MyRectangle.Stroke = Brushes.Blue;
Grid1.Children.Add(MyRectangle);
}
void button2_Click(object sender, RoutedEventArgs e)
{
//绘制一个简单的矩形,Geometry 类
//http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.media.geometry.aspx
RectangleGeometry myRectangleGeometry1 = new RectangleGeometry(new Rect(new Size(, )));
Path myPath1 = new Path();
myPath1.Margin = new Thickness(, , , );
myPath1.Stroke = Brushes.Red;
myPath1.Fill = Brushes.Gold;
myPath1.StrokeThickness = ;
myPath1.Data = myRectangleGeometry1;
Grid1.Children.Add(myPath1); RectangleGeometry myRectangleGeometry2 = new RectangleGeometry(new Rect(new Size(, )));
Path myPath2 = new Path();
myPath2.Margin = new Thickness(, , , );
myPath2.Stroke = Brushes.Red;
myPath2.Fill = Brushes.SpringGreen;
myPath2.StrokeThickness = ;
myPath2.Data = myRectangleGeometry2; Grid1.Children.Add(myPath2); }
void button3_Click(object sender, RoutedEventArgs e)
{
//绘制圆
EllipseGeometry eg1 = new EllipseGeometry(new Point(, ), , );
EllipseGeometry eg2 = new EllipseGeometry(new Point(, ), , );
EllipseGeometry eg3 = new EllipseGeometry(new Point(, ), , );
EllipseGeometry eg4 = new EllipseGeometry(new Point(, ), , ); //区域进行合并,可以求交集,并集....其它等; CombinedGeometry cg1 = new CombinedGeometry(GeometryCombineMode.Xor, eg1, eg2);
CombinedGeometry cg2 = new CombinedGeometry(GeometryCombineMode.Xor, eg3, eg4); //绘制
Path myPath = new Path();
myPath.Margin = new Thickness(, , , );
myPath.Stroke = Brushes.SeaGreen;
myPath.Fill = Brushes.Violet;
myPath.StrokeThickness = ;
myPath.Data = cg1;
Grid1.Children.Add(myPath); Path myPath1 = new Path();
myPath1.Margin = new Thickness(, , , );
myPath1.Stroke = Brushes.SeaGreen;
myPath1.Fill = Brushes.Violet;
myPath1.StrokeThickness = ;
myPath1.Data = cg2;
Grid1.Children.Add(myPath1); } }
}

上面的实例也简单的展示了效果,更多的运用我们可以从msdn上,上面有详细的说明,以及运用方法

demo示例:http://files.cnblogs.com/BABLOVE/WPF2D%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2%E6%96%B9%E6%B3%95.rar

WPF2D绘制图形方法的更多相关文章

  1. PCB ODB++(Gerber)图形绘制实现方法

    这里讲解一下用net解析PCB图形绘制实现方法 一.解析PCB图形绘制实现 解析PCB图形,说简单也非常简单,先说一下,PCB Gerber图形由:点,线,弧,铜皮,文字 5类元素组成,通常简写为:P ...

  2. html5 Canvas绘制图形入门详解

    html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...

  3. 11-UIKit(Storyboard、View的基本概念、绘制图形、UIBezierPath)

    目录: 1. Storyboard 2. Views 3. View的基本概念介绍 4. 绘制图形 5. UIBezierPath 回到顶部 1. Storyboard 1.1 静态表视图 1)Sec ...

  4. HTML5—canvas绘制图形(1)

    1.canvas基础知识 canvas元素是HTML5中新增的一个重要的元素,专门用来绘制图形,不过canvas本身不具备画图的能力,在页面中放置了canvas元素,就相当于在页面中放置了一块矩形的“ ...

  5. 【canvas学习笔记二】绘制图形

    上一篇我们已经讲述了canvas的基本用法,学会了构建canvas环境.现在我们就来学习绘制一些基本图形. 坐标 canvas的坐标原点在左上角,从左到右X轴坐标增加,从上到下Y轴坐标增加.坐标的一个 ...

  6. HTML5使用Canvas来绘制图形

    一.Canvas标签: 1.HTML5<canvas>元素用于图形的绘制,通过脚本(通常是javascript)来完成. 2.<canvas>标签只是图形容器,必须使用脚本来绘 ...

  7. Java 在PPT中绘制图形

    Microsoft PowerPoint可支持在幻灯片中插入各种类型的图形并且可设置图形填充.线条颜色.图形大小.位置等.下面将通过Java编程来演示在PPT中绘制图形的方法. 工具:Free Spi ...

  8. Java 在PDF文档中绘制图形

    本篇文档将介绍通过Java编程在PDF文档中绘制图形的方法.包括绘制矩形.椭圆形.不规则多边形.线条.弧线.曲线.扇形等等.针对方法中提供的思路,也可以自行变换图形设计思路,如菱形.梯形或者组合图形等 ...

  9. 实现绘制图形的ToolBar

    给地图添加绘制图形的ToolBar还是有必要的,比较人性化的功能.图形的样式可以自己定制,也提供了朴实的默认样式.对 dojo 不太懂,出现了许许多多问题,真是蛋疼的一天啊.令人惊喜的是 ArcGis ...

随机推荐

  1. IO 流—>>>补充

    流操作规律: 示例:1. 源: 键盘录入 目的: 控制台 2.源:文件 目的:控制台 3.源: 键盘录入 目的: 文件 基本规律: 面对流对象很多,不知道用哪一个的时候: 通过两个明确来完成 1.明确 ...

  2. 3proxy代理软件文档说明

    官方英文原版说明:http://www.3proxy.ru/howtoe.asp 配置文件的简要说明:如果你的英文理解力好,可以试着研究一下他的手册. 以实例说明吧 nscache 65536域名解析 ...

  3. HDU2028JAVA

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. Hadoop书籍汇总

    <Hadoop实战>陆嘉恒 <Hadoop - The Definitive Guide>Tom White,中文版<Hadoop权威指南> <Hadoop技 ...

  5. C#将DataTable导出Execl、Word、Xml

        /// <summary>     /// 将DT转换为Execl的方法     /// </summary>     /// <param name=" ...

  6. HTML+CSS基础学习笔记(3)

    一.提交按钮.重置按钮 1.type="submit" 提交按钮 2.type="reset"   重置按钮 二.form表单中的label标签 格式: < ...

  7. (转)Spring 读书笔记-----使用Spring容器(一)

    Spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spr ...

  8. java 内部类学习

    类和内部类的关系就如同人和心脏的关系. 实例1:内部类的基本结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 //外部 ...

  9. js基础知识之_对象

    javascript 对象 1.基于对象 一切皆对象,以对象的概念来编程 2.面向对象的编程(oop,Object oriented programming) 1.对象 就是人们要研究的任何事物,不仅 ...

  10. sql - 查询所有表中包含指定值

    可以直接创建sql语句: CREATE TABLE qResults (tName nvarchar(370), cname nvarchar(3630),[count] int) declare @ ...