xaml:

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="418" Width="525">
<DockPanel LastChildFill="True">
<StackPanel MinWidth="100" DockPanel.Dock="Left">
<TextBlock HorizontalAlignment="Center">editing mode</TextBlock>
<Button x:Name="btnselection" Margin="5" Click="btnselection_Click">selection</Button>
<Button x:Name="btndraw" Margin="5" Click="btndraw_Click">draw</Button>
<Button x:Name="btnerase" Margin="5" Click="btnerase_Click">erase</Button> <TextBlock HorizontalAlignment="Center">choss color:</TextBlock>
<Ellipse x:Name="rectred" Fill="Red" MinHeight="50" Margin="5" MouseDown="rectred_MouseDown"></Ellipse>
<Ellipse x:Name="rectgreen" Fill="Green" MinHeight="50" Margin="5" MouseDown="rectgreen_MouseDown"></Ellipse>
<Ellipse x:Name="rectblue" Fill="Blue" MinHeight="50" Margin="5" MouseDown="rectblue_MouseDown"></Ellipse>
<Ellipse x:Name="rectyellow" Fill="Yellow" MinHeight="50" Margin="5"></Ellipse>
</StackPanel>
<InkCanvas x:Name="inkcanvas1" EditingMode="Ink" ClipToBounds="True"> </InkCanvas>
</DockPanel>
</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 WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); } private void btnerase_Click(object sender, RoutedEventArgs e)
{
inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.EraseByPoint;
} private void rectred_MouseDown(object sender, MouseButtonEventArgs e)
{
inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Red;
} private void btndraw_Click(object sender, RoutedEventArgs e)
{
inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.Ink;
} private void rectgreen_MouseDown(object sender, MouseButtonEventArgs e)
{
inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Green;
} private void rectblue_MouseDown(object sender, MouseButtonEventArgs e)
{
inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Blue;
} private void rectyellow_MouseDown(object sender, MouseButtonEventArgs e)
{
inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Yellow;
;
} private void btnselection_Click(object sender, RoutedEventArgs e)
{
inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.Select;
} }
}

效果:

wpf简单的绘图板的更多相关文章

  1. Windows Phone开发(21):做一个简单的绘图板

    原文:Windows Phone开发(21):做一个简单的绘图板 其实我们今天要说的就是一个控件--InkPresenter,这个控件并不是十分强大,没办法和WPF中的InkCanvas相比,估计在实 ...

  2. WPF简单入门总结

    WPF简单总结 最近看了点关于WPF的东西,总结了点点入门的东西. XAML语法基础 1.  定义样式 <Window.Resources><!--窗体资源的定义--> < ...

  3. wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合

    wpf 导出Excel   1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...

  4. .NET CORE(C#) WPF简单菜单MVVM绑定

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF简单菜单MVVM绑定 阅读导航 本文背景 代码实现 本文参考 ...

  5. WPF简单导航框架(Window与Page互相调用)

    相当多的WPF程序都有着丰富的页面和功能,如何使程序在不同页面间转换并降低资源占用,选择适合自己的导航框架就很重要了.最近花了一点时间做了一个简单的导航框架,并在这个过程中对Window.Page.U ...

  6. WPF简单布局 浅尝辄止

            WPF的窗口只能包含一个元素,为了在WPF窗口中放置多个元素并创建更实用的用户界面,需要在窗口上放置一个容器,然后在容器中放置其它元素. 注意:造成这一限制的原因是window类继承自 ...

  7. Wpf 简单制作自己的窗体样式(2)

    上一篇blog讲了制作简单的样式的窗体,对于一个传统的窗体,不仅仅可以拖动,和关闭操作.还具有最大化.最小化.隐藏,以及改变窗体的大小等.这篇blog就是对上篇的补充,完善窗体的改变大小和最大化最小化 ...

  8. Wpf 简单制作自己的窗体样式

    最近一直在搞wpf相关的东东,由于还在门外徘徊,所以第一篇blog写了简单的制作扁平化的wpf button样式,这一篇也简单的制作属于自己wpf 窗体的样式. 废话少说,下面就开始制作自己的窗体样式 ...

  9. WPF简单的数据库查询

    做一个简单WPF连接数据库的 控件类型和名称:DataGrid:dataGrid          Button1  :Button1              Button:   Button2   ...

随机推荐

  1. No manual entry for pthread_mutex_init .

    $manpthread_mutex_init No manual entryfor pthread_mutex_init 解决方案: $sudo apt-get install manpages-po ...

  2. C/C++——[02] 运算符和表达式

    C/C++中表示数据运算的符号称为“运算符”.运算符所用到的操作数个数,称为运算符的“目数”. C/C++语言的运算符有赋值运算符.算术运算符.逻辑运算符.位运算符等多类. 将变量.常量等用运算符连接 ...

  3. linux c下输入密码不回显

    今天做一个登录程序,需要屏蔽掉密码,于是自己就在网上找资料,找到了一种和linux终端下输入密码方式相同的方法,不显示在终端,具体代码实现如下. #include<stdio.h> #in ...

  4. MVC – 4.mvc初体验(1)

    1.MVC请求模式 2.MVC简单请求流程图 展开 折叠 3.返回string的mvc方法 展开 折叠 4.加载视图的方法

  5. 解决 VUE 微信 IOS 路由跳转问题

    watch: { "$route"(){ if (/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)) { location.hre ...

  6. Mybatis异常处理之MySQL Connector Java] will not be managed by Spring

    很长时间没写后台代码有点生疏了,这不今天又出点小插曲,写个文章记录下. 由于要上传点数据到后台,顺手整了个mybatis+springmvc.在保存数据时出现了异常. Creating a new S ...

  7. Mybatis处理列名—字段名映射— 驼峰式命名映射

    规范命名,数据库字段名使用 : 下划线命名(user_id) 类属性使用 : 驼峰命名(userId) 配置mybatis 时,全局设置: <settings> <!-- 开启驼峰, ...

  8. Java List转换为字符串的几种方法

    Java List转换为字符串的几种方法 import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import ...

  9. office2016破解激活安装

    昨天一室友装office2016不会激活,[嘲讽脸]真的是笨啊.我这是在一个社区论坛里面找到的. 在网上找了教程,有些没用的,所以记录安装教程以便之后查看.以下的安装激活亲测有效(2017-4-28) ...

  10. 洛谷P3457 [POI2007]POW-The Flood [并查集,模拟]

    题目传送门 pow 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是 ...