WPF2D绘制图形方法
我们先看看效果如何:
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绘制图形方法的更多相关文章
- PCB ODB++(Gerber)图形绘制实现方法
这里讲解一下用net解析PCB图形绘制实现方法 一.解析PCB图形绘制实现 解析PCB图形,说简单也非常简单,先说一下,PCB Gerber图形由:点,线,弧,铜皮,文字 5类元素组成,通常简写为:P ...
- html5 Canvas绘制图形入门详解
html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...
- 11-UIKit(Storyboard、View的基本概念、绘制图形、UIBezierPath)
目录: 1. Storyboard 2. Views 3. View的基本概念介绍 4. 绘制图形 5. UIBezierPath 回到顶部 1. Storyboard 1.1 静态表视图 1)Sec ...
- HTML5—canvas绘制图形(1)
1.canvas基础知识 canvas元素是HTML5中新增的一个重要的元素,专门用来绘制图形,不过canvas本身不具备画图的能力,在页面中放置了canvas元素,就相当于在页面中放置了一块矩形的“ ...
- 【canvas学习笔记二】绘制图形
上一篇我们已经讲述了canvas的基本用法,学会了构建canvas环境.现在我们就来学习绘制一些基本图形. 坐标 canvas的坐标原点在左上角,从左到右X轴坐标增加,从上到下Y轴坐标增加.坐标的一个 ...
- HTML5使用Canvas来绘制图形
一.Canvas标签: 1.HTML5<canvas>元素用于图形的绘制,通过脚本(通常是javascript)来完成. 2.<canvas>标签只是图形容器,必须使用脚本来绘 ...
- Java 在PPT中绘制图形
Microsoft PowerPoint可支持在幻灯片中插入各种类型的图形并且可设置图形填充.线条颜色.图形大小.位置等.下面将通过Java编程来演示在PPT中绘制图形的方法. 工具:Free Spi ...
- Java 在PDF文档中绘制图形
本篇文档将介绍通过Java编程在PDF文档中绘制图形的方法.包括绘制矩形.椭圆形.不规则多边形.线条.弧线.曲线.扇形等等.针对方法中提供的思路,也可以自行变换图形设计思路,如菱形.梯形或者组合图形等 ...
- 实现绘制图形的ToolBar
给地图添加绘制图形的ToolBar还是有必要的,比较人性化的功能.图形的样式可以自己定制,也提供了朴实的默认样式.对 dojo 不太懂,出现了许许多多问题,真是蛋疼的一天啊.令人惊喜的是 ArcGis ...
随机推荐
- 仿写自己的一个加载语言包的L函数
<?php /** * [L 加载语言的L的方法] * @param [string] $key [语言键的名称] * @return [string] $value [取到的语言值] */ f ...
- Mysql Binlog 三种格式介绍及分析
一.Mysql Binlog格式介绍 Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的sql都会记录在 ...
- WPF DataGrid 合并单元格
在网上搜索wpf合并单元格,一直没搜索到,没办法,只能自己想办法搞定了.其实就是DataGrid套DataGrid,为了方便支持Column拖动,在合并的DataGridColumn那一列的Heade ...
- 03 将MDB文件在DATAGRID中显示
附件:http://files.cnblogs.com/xe2011/MDB_BindingSource.rar using System; using System.Collections.Gene ...
- linux kernel (proc文件系统)参数
http://blog.csdn.net/guowake/article/details/3279796 Linux Proc文件系统,通过对Proc文件系统进行调整,达到性能优化的目的. 二./pr ...
- 如何调试PHP的Core之获取基本信息 --------风雪之隅 PHP7核心开发者
http://www.laruence.com/2011/06/23/2057.html https://github.com/laruence PHP开发组成员, Zend兼职顾问, PHP7核心开 ...
- GUI之CCControlExtension
Introduction CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. ...
- Linux下rsync增加SSH端口号的用法
rsync默认使用SSH的22号端口,为了安全起见,很多机器更改了SSH默认的端口号,对应rsync命令的用法为: rsync -e 'ssh -p 1234' username@hostname:S ...
- ashx+html+ajax
HTML: $(function() { ajax("NewsList.ashx", function(resText) { document.getElementById(&qu ...
- Struts2,Hibernate和Spring之间的框架整合关系
1.首先要认清,hibernate和struts没有半点关系,所以他们之间没有任何可以整合的东西.a:struts 作为中心控制器,肯定要调用一些类来完成一些逻辑.而hibernate开发中,经常使用 ...