Windows系统自带的画图工具很完善的,如下代码只是演示创建一个简易的画板,可以做教学使用。

整体效果如下:

1. 添加组件System.Windows.Controls.Ribbon

2. 界面设计

<Window x:Class="PEN.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:PEN"mc:Ignorable="d"Background="#FF73DC73"Title="演示画板" Height="450" Width="800"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="\*"/></Grid.RowDefinitions><Ribbon x:Name="ribbon" Grid.Row="0"><Ribbon.Resources><Style TargetType="RibbonRadioButton"><Setter Property="CornerRadius" Value="13"/><Setter Property="Margin" Value="5 0 0 0"/><EventSetter Event="Checked" Handler="RibbonRadioButton\_Checked"/></Style></Ribbon.Resources><Ribbon.ApplicationMenu><RibbonApplicationMenu Visibility="Collapsed"/></Ribbon.ApplicationMenu><RibbonTab x:Name="rt1" Header="画板 "><RibbonGroup Header="笔画类型"><RibbonRadioButton x:Name="rrbPen" Label="钢笔" IsChecked="True" LargeImageSource="Images/P1.png"/><RibbonRadioButton x:Name="rrbHighlighter" LargeImageSource="Images/P2.png" Label="荧光笔"/></RibbonGroup><RibbonGroup Header="钢笔颜色"><RibbonRadioButton Label="红色" IsChecked="True"  LargeImageSource="Images/red.png"/><RibbonRadioButton Label="绿色"  LargeImageSource="Images/green.png"/><RibbonRadioButton Label="蓝色"  LargeImageSource="Images/blue.png"/></RibbonGroup><RibbonGroup Header="编辑选项"><RibbonRadioButton x:Name="rrbInk" Label="墨迹" IsChecked="True" LargeImageSource="Images/b1.png"  GroupName="edit" /><RibbonRadioButton Label="手势" GroupName="edit" LargeImageSource="Images/hand.png"  /><RibbonRadioButton Label="套索选择" LargeImageSource="Images/config.png"  GroupName="edit" /><RibbonRadioButton Label="点擦除" LargeImageSource="Images/erase2.png"  GroupName="edit" /><RibbonRadioButton Label="笔画擦除" LargeImageSource="Images/erase1.png" GroupName="edit" /></RibbonGroup></RibbonTab></Ribbon><InkCanvas Name="ink1" Grid.Row="1" Background="#FFFFF9F5"/></Grid></Window>

设计效果:

3. 后台代码设计

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.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.Windows.Controls.Ribbon;namespace PEN{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{private DrawingAttributes inkDA;private DrawingAttributes highlighterDA;private Color currentColor;public MainWindow(){InitializeComponent();currentColor = Colors.Red;inkDA = new DrawingAttributes(){Color = currentColor,Height = 6,Width = 6,FitToCurve = false};highlighterDA = new DrawingAttributes(){Color = Colors.Orchid,IsHighlighter = true,IgnorePressure = false,StylusTip = StylusTip.Rectangle,Height = 30,Width = 10};ink1.DefaultDrawingAttributes = inkDA;ink1.EditingMode = InkCanvasEditingMode.Ink;}private void RibbonRadioButton\_Checked(object sender, RoutedEventArgs e){string name = (e.Source as RibbonRadioButton).Label;switch (name){case "钢笔":InitColor();ink1.EditingMode = InkCanvasEditingMode.Ink;break;case "荧光笔":highlighterDA = new DrawingAttributes(){Color = currentColor ,IsHighlighter = true,IgnorePressure = false,StylusTip = StylusTip.Rectangle,Height = 30,Width = 10};ink1.DefaultDrawingAttributes = highlighterDA;break;case "红色":currentColor = Colors.Red;InitColor();break;case "绿色":currentColor = Colors.Green;InitColor();break;case "蓝色":currentColor = Colors.Blue;InitColor();break;case "墨迹": ink1.EditingMode = InkCanvasEditingMode.Ink; break;case "手势": ink1.EditingMode = InkCanvasEditingMode.GestureOnly; break;case "套索选择": ink1.EditingMode = InkCanvasEditingMode.Select; break;case "点擦除": ink1.EditingMode = InkCanvasEditingMode.EraseByPoint; break;case "笔画擦除": ink1.EditingMode = InkCanvasEditingMode.EraseByStroke; break;}}private void InitColor(){inkDA.Color = currentColor;rrbPen.IsChecked = true;ink1.DefaultDrawingAttributes = inkDA;}}}

可做简单的教学演示工具,可以做演算的小白板。

WPF中使用Windows.Controls.Ribbon创建一个简单画板相关推荐

  1. Windows下编译TensorFlow1.3 C++ library及创建一个简单的TensorFlow C++程序

    参考:https://www.cnblogs.com/jliangqiu2016/p/7642471.html Windows下编译TensorFlow1.3 C++ library及创建一个简单的T ...

  2. c# WPF中System.Windows.Interactivity的使用

    背景 在我们进行WPF开发应用程序的时候不可避免的要使用到事件,很多时候没有严格按照MVVM模式进行开发的时候习惯直接在xaml中定义事件,然后再在对应的.cs文件中直接写事件的处理过程,这种处理方式 ...

  3. 使用 Windows Virtual PC 创建一个虚拟机

    之前我们对 Windows Virtual PC & Windows XP Mode 有所了解!除了可以用于解决企业中所遇到的应用程序兼容性问题以外,其实通过 Windows Virtual ...

  4. 创建一个简单的应用程序窗口,显示“欲穷千里目 更上一层楼”。这一行文字从窗口中向左滚动显示,而且每显示一轮,改变一次颜色,改变一次字体,一个周期为4种颜色,分别为红、绿、黄、蓝,四种字体分别为宋体、楷

    创建一个简单的应用程序窗口,显示"欲穷千里目 更上一层楼".这一行文字从窗口中向左滚动显示,而且每显示一轮,改变一次颜色,改变一次字体,一个周期为4种颜色,分别为红.绿.黄.蓝,四 ...

  5. 关于WPF 中 “System.Windows.Markup.XamlParseException”类型的未经处理的异常在 PresentationFramework.dll 中发生 异常的处理。

    关于WPF 中 "System.Windows.Markup.XamlParseException"类型的未经处理的异常在 PresentationFramework.dll 中发 ...

  6. python如何创建一个列表_使用python中的format()创建一个列表(make a list using format() in python)...

    使用python中的format()创建一个列表(make a list using format() in python) 我是python和编码的新手. 因此,如果已经讨论过这件事,我很抱歉,我无 ...

  7. C#游戏编程之创建一个简单的卷轴射击游戏

    前几天很多朋友要求贴一篇有关C#游戏开发的实例.本篇文章是创建一个简单的卷轴射击游戏开发实例,内容比较完整,分享给大家,不过篇幅有些长,可以慢慢看哈!本文除CSDN博客外,任何媒体和出版物禁止转载和使 ...

  8. Beginning WF4读书笔记(一):创建一个简单的工作流

    让我们以创建一个简单的工作流开始.开启Visual Studio (VS) 2010,选择New Project.在已经安装的模版下面,选择Visual C#-Workflow,你会看到提供了四个模版 ...

  9. 创建一个简单的WCF程序

    为了使读者对基于WCF的编程模型有一个直观的映像,我将带领读者一步一步地创建一个完整的WCF应用.本应用功能虽然简单,但它涵盖了一个完整WCF应用的基本结构.对那些对WCF不是很了解的读者来说,这个例 ...

最新文章

  1. mysql中char与varchar的区别分析(补充一句,int和integer没区别)
  2. 吃货告诉你IaaS、PaaS、SaaS之间的区别
  3. JAVA学习日记DAY1
  4. Python+Appium自动化测试之toast定位
  5. C#获取动态代码的值
  6. 史上最全Java多线程面试题及答案
  7. 从内核层说清GetMessage , DispatchMessage
  8. canvas并查集画随机迷宫
  9. Python判断一个字符串是否包含某个指定的字符串
  10. 使用redis实现订阅功能
  11. spark | scala | 线性代数库Breeze学习
  12. linux 基础训练题,Linux习题练习
  13. 软件测试的知识点总结
  14. 龙芯指令集也可以开源
  15. CF989C A Mist of Florescence
  16. Apache配置虚拟主机后,不能访问localhost的问题
  17. Linux(1)之文件“776”
  18. rpc wmi 服务不可用_wmi服务是什么?wmi服务常见问题及解决技巧!
  19. 山东大学计算机考研909真题,2012年山东大学909数据结构考研试题(回忆版)
  20. 【MockJS】使用MockJS模拟数据 (超级详细)

热门文章

  1. C 数据类型(bit,byte,word;char,int,long;float,double)
  2. 2021年G2电站锅炉司炉考试及G2电站锅炉司炉考试资料
  3. 155-161 李游前端精品课程笔记
  4. oak深度相机入门教程-Mask R-CNN 算法
  5. 解决安卓手机动画效果无效问题
  6. 关于计算机应用基础论文,关于计算机应用基础论文范文.docx
  7. Android购物软件制作(毕业设计)
  8. wav格式的音乐怎么转换?
  9. java 队列方法详解
  10. tomcat启动了,部署的项目没有加载