稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)

时间:2023-01-21 12:14:51
[索引页]
[源码下载]


稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)


作者: webabcd


介绍
Silverlight 2.0 人机交互:InkPresenter(涂鸦板)
    InkPresenter - 涂鸦板,也就是在面板上呈现墨迹。InkPresenter 可以包含子控件
    Cursor - 鼠标移动到 InkPresenter 上面时,鼠标指针的样式
    Background - 涂鸦板背景
    Opacity - 面板上墨迹的不透明度
    Clip - InkPresenter 的剪辑区域
    Stroke.DrawingAttributes - Stroke(笔划)的外观属性
    UIElement.CaptureMouse() - 为 UIElement 对象启用鼠标捕捉
    UIElement.ReleaseMouseCapture() - 为 UIElement 对象释放鼠标捕捉


在线DEMO
http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html


示例
InkPresenter.xaml
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)< UserControl  x:Class ="Silverlight20.Interactive.InkPresenter"
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    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"  mc:Ignorable ="d" >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    
< Canvas >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- InkPresenter 的外围的带边框的背景图 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Rectangle  Width ="420"  Height ="350"  Stroke ="Black"  StrokeThickness ="1" >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
< Rectangle.Fill >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
< ImageBrush  ImageSource ="/Silverlight20;component/Images/Background.jpg"  Stretch ="Fill"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
</ Rectangle.Fill >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
</ Rectangle >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 用于描绘 InkPresenter 的工作区 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Rectangle  Canvas.Top ="10"  Canvas.Left ="10"  Width ="400"  Height ="300"  RadiusX ="25"  RadiusY ="25"  Fill ="Black"  Opacity ="0.2"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!--
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        InkPresenter - 涂鸦板,也就是在面板上呈现墨迹
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            Cursor - 鼠标移动到 InkPresenter 上面时,鼠标指针的样式
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                Arrow - 箭头
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                Hand - 手形 
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                Wait - 沙漏
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                IBeam - “I”字形 
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                Stylus - 点
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                Eraser - 橡皮
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                None - 无
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            Background - 涂鸦板背景。建议设置其为“Transparent”,需要的话可以使用其他控件来描绘背景
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            Opacity - 面板上墨迹的不透明度
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            Clip - InkPresenter 的剪辑区域。本例给 InkPresenter 做了一个圆角效果,其Clip值由 Blend 生成
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
-->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< InkPresenter  x:Name ="inkPresenter"  Cursor ="Stylus"  Canvas.Top ="10"  Canvas.Left ="10"  Width ="400"  Height ="300"  Background ="Transparent"
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)         
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            MouseLeftButtonDown
="inkPresenter_MouseLeftButtonDown"  
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            MouseLeftButtonUp
="inkPresenter_MouseLeftButtonUp"  
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            MouseMove
="inkPresenter_MouseMove"  
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            Clip
="M0.5,25.5 C0.5,11.692882 11.692882,0.5 25.5,0.5 L374.5,0.5 C388.30713,0.5 399.5,11.692882 399.5,25.5 L399.5,274.5 C399.5,288.30713 388.30713,299.5 374.5,299.5 L25.5,299.5 C11.692882,299.5 0.5,288.30713 0.5,274.5 z" >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
<!--
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            InkPresenter 可以包含子控件。本例为在 InkPresenter 的底部循环播放视频
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
-->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
< MediaElement  x:Name ="mediaElement"  Source ="/Silverlight20;component/Video/Demo.wmv"  Width ="400"  Height ="100"  Canvas.Top ="200"  Stretch ="UniformToFill"  MediaEnded ="mediaElement_MediaEnded"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
</ InkPresenter >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 红色取色点,点此后可画红色的线 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Ellipse  x:Name ="ellipseRed"  Canvas.Top ="320"  Canvas.Left ="20"  Cursor ="Hand"  Fill ="Red"  Width ="20"  Height ="20"  MouseLeftButtonDown ="ellipseRed_MouseLeftButtonDown"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 黑色取色点,点此后可画黑色的线 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Ellipse  x:Name ="ellipseBlack"  Canvas.Top ="320"  Canvas.Left ="50"  Cursor ="Hand"  Fill ="Black"  Width ="20"  Height ="20"  MouseLeftButtonDown ="ellipseBlack_MouseLeftButtonDown"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 橡皮擦,点此后可擦除之前画的线 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Button  x:Name ="btnEraser"  Canvas.Top ="320"  Canvas.Left ="80"  Content ="橡皮擦"  Click ="btnEraser_Click"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 用于清除 InkPresenter 上的墨迹的按钮 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< Button  x:Name ="btnClear"  Canvas.Top ="320"  Canvas.Left ="130"  Content ="清除"  Click ="btnClear_Click"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
<!-- 用于显示当前 Stroke(笔划) 所在的 矩形范围 的位置信息 -->
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
< TextBox  x:Name ="txtMsg"  Canvas.Top ="320"  Canvas.Left ="180"  Width ="220"   />
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)           
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    
</ Canvas >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
</ UserControl >
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)

InkPresenter.xaml.cs
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)using  System;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Collections.Generic;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Linq;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Net;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Controls;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Documents;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Input;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Media;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Media.Animation;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Shapes;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Windows.Ink;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.Xml.Linq;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.ServiceModel;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
using  System.ServiceModel.Channels;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
namespace  Silverlight20.Interactive
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    
public partial class InkPresenter : UserControl
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
// 在涂鸦板上描绘的笔划
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
        private System.Windows.Ink.Stroke _newStroke;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
// 在涂鸦板上描绘的笔划的颜色
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
        private System.Windows.Media.Color _currentColor = Colors.Red;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
// 是否是擦除操作
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
        private bool _isEraser = false;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
// 当前是否正在 InkPresenter 上捕获鼠标
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
        private bool _isCapture = false;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
public InkPresenter()
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            InitializeComponent();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
void inkPresenter_MouseLeftButtonDown(object sender, MouseEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// UIElement.CaptureMouse() - 为 UIElement 对象启用鼠标捕捉
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 为 InkPresenter 启用鼠标捕捉
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            inkPresenter.CaptureMouse();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _isCapture 
= true;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
if (_isEraser)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// 擦除鼠标当前位置所属的 Stroke(笔划)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                RemoveStroke(e);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
else
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Input.MouseEventArgs.StylusDevice.Inverted - 是否正在使用手写笔(tablet pen)的辅助笔尖
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Ink.Stroke.DrawingAttributes - Stroke(笔划)的外观属性
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Ink.Stroke.DrawingAttributes.Width - 笔划的宽
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Ink.Stroke.DrawingAttributes.Height - 笔划的高
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Ink.Stroke.DrawingAttributes.Color - 笔划的颜色
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// System.Windows.Ink.Stroke.DrawingAttributes.OutlineColor - 笔划的外框的颜色
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                _newStroke 
= new System.Windows.Ink.Stroke();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                _newStroke.DrawingAttributes.Width 
= 3d;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                _newStroke.DrawingAttributes.Height 
= 3d;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                _newStroke.DrawingAttributes.Color 
= _currentColor;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                _newStroke.DrawingAttributes.OutlineColor 
= Colors.Yellow;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// 为 Stroke(笔划) 在当前鼠标所在位置处增加 StylusPoint(点)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                _newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter));
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// 将设置好的 Stroke(笔划) 添加到 InkPresenter 的 Strokes(笔划集) 中
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                inkPresenter.Strokes.Add(_newStroke);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// Stroke.GetBounds() - 获取当前 Stroke(笔划) 所在的 矩形范围 的位置信息
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// Strokes.GetBounds() - 获取当前 Strokes(笔划集) 所在的 矩形范围 的位置信息
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// 显示该 Stroke(笔划) 所在的 矩形范围 的位置信息
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                Rect rect = _newStroke.GetBounds();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                txtMsg.Text 
= string.Format("上:{0}; 下:{1}; 左:{2}; 右:{3}",
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                   rect.Top, rect.Bottom, rect.Left, rect.Right);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
void inkPresenter_MouseMove(object sender, MouseEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
if (_isCapture)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
if (_isEraser)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                    
// 擦除鼠标当前位置所属的 Stroke
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                    RemoveStroke(e);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
else if (_newStroke != null)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                    
// 为已经添加到 InkPresenter 的 Strokes 中的 Stroke 增加 StylusPoint
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                    _newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter));
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                    
// 显示该 Stroke 所在的 矩形范围 的位置信息
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                    Rect rect = _newStroke.GetBounds();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                    txtMsg.Text 
= string.Format("上:{0}; 下:{1}; 左:{2}; 右:{3}",
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                           rect.Top, rect.Bottom, rect.Left, rect.Right);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
void inkPresenter_MouseLeftButtonUp(object sender, MouseEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// UIElement.CaptureMouse() - 为 UIElement 对象释放鼠标捕捉
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 为 InkPresenter 释放鼠标捕捉
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            inkPresenter.ReleaseMouseCapture();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _newStroke 
= null;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _isCapture 
= false;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
void RemoveStroke(MouseEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// Stroke.HitTest(StylusPointCollection) -  Stroke 是否与指定的 StylusPoint 集合相连
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// Strokes.HitTest(StylusPointCollection) - 与指定的 StylusPoint 集合相连的 Stroke 集合
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 获取当前鼠标所在位置处的 StylusPoint 集合
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            StylusPointCollection erasePoints = new StylusPointCollection();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            erasePoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter));
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 与当前鼠标所在位置处的 StylusPoint 集合相连的 Stroke 集合
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            StrokeCollection hitStrokes = inkPresenter.Strokes.HitTest(erasePoints);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
for (int i = 0; i < hitStrokes.Count; i++)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)                
// 在 InkPresenter 上清除指定的 Stroke
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
                inkPresenter.Strokes.Remove(hitStrokes[i]);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
private void mediaElement_MediaEnded(object sender, RoutedEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 视频播放完后,再重新播放
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            mediaElement.Position = TimeSpan.FromMilliseconds(0);
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            mediaElement.Play();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
private void ellipseRed_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 单击了 红色取色点
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            _currentColor = Colors.Red;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            inkPresenter.Cursor 
= Cursors.Stylus;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _isEraser 
= false;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
private void ellipseBlack_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 单击了 黑色取色点
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            _currentColor = Colors.Black;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            inkPresenter.Cursor 
= Cursors.Stylus;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _isEraser 
= false;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
private void btnClear_Click(object sender, RoutedEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 单击了 清除 按钮
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            inkPresenter.Strokes.Clear();
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
private void btnEraser_Click(object sender, RoutedEventArgs e)
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        
{
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            
// 单击了 橡皮擦 按钮
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)
            inkPresenter.Cursor = Cursors.Eraser;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)            _isEraser 
= true;
稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)        }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)    }

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)}

稳扎稳打Silverlight(14) - 2.0交互之InkPresenter(涂鸦板)


OK
[源码下载]