我们先看看效果如何:

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. 高性能爬虫为什么使用定制DNS客户端?

    DNS 解析是高性能网络爬虫的瓶颈,主要是因为: 1. 由于域名服务的分布式的特性,DNS解析可能需要多次的请求转发,有时需要几秒甚至更长的时间来解析出相应的IP 地址. 2. 现有的标准库对DNS解 ...

  2. Android开发之TextView的下划线添加

    如何给TextView添加下划线呢,最近项目中需要这个,于是就用代码添加了下划线功能.主要就是用Paint的setFlags方法来实现,具体如下: ((TextView)mScrollView.fin ...

  3. 字符串右移n位(C++实现)

    字符串右移n位(C++实现): // ShiftNString.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <i ...

  4. Android(java)学习笔记195:三重for循环的优化(Java面试题)

    1.首先我们看一段代码: for(int i=0;i<1000;i++){ for(int j=0;j<100;j++){ for(int k=0;k<10;k++){ testFu ...

  5. 使用Android Studio时so文件打包不到APK中

    1,需要在build中添加如下配置,这是必备的 Android {   sourceSets {       main {           jniLibs.srcDirs = ['libs']   ...

  6. BI任务列表

    了解点击流系统和pv/uv的相关计算 关于pv的那些事!! ···············································2014-09-10 homework做了些什 ...

  7. CI框架篇之模型篇--AR操作(2)

    CodeIgniter 和众多的框架一样,有属于自己的一套对数据库的操作方式,本框架更是如此 有属于自己的一套对数据库的安全并且简单的操作, 成为AR操作:下面来对AR操作进行介绍: 首先,确定要启动 ...

  8. window 安装 Protobuf

    环境安装 1:下载CMake 2:打开VS Command Prompt 3:修改工作目录到目标目录 cd C:\Path\to 4:创建编译完后 protobuf headers/libraries ...

  9. Update Statistics用法

    Update Statistics语句的作用将创建的数据库表的有关统计信息更新到系统 sysmater的相关表中,以便查询优化器选择最佳的执行路径,当sysmaster库中没有相应的统计信息,或者统计 ...

  10. 百度,人人,新浪,腾讯等分享Js代码

    <!-- Baidu Button BEGIN -->                        <div id="bdshare" class=" ...